国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

跟著視頻學 c# asp.net 第二天

2019-11-17 02:42:28
字體:
來源:轉載
供稿:網(wǎng)友

跟著視頻學 c# asp.net 第二天

課程要點:

把變量看成存放數(shù)據(jù)的容器 定義變量的方式:類型 變量名; int i3;變量只是容器,必須放進去值才有意義,否則就沒有意義. int i2=5;變量的類型:不同類型的容器放不同的東西。不能在int類型的變量中放字符串。變量不能放和變量類型不兼容的數(shù)據(jù)。string、int 、char 、bool long等。bool的取值:true、false。int的表示范圍。long有多l(xiāng)ong為什么輸出"要用轉義符"/"",因為編譯器默認是遇到"開始字符串,再遇到"是結束字符串,但是如果遇到前面有/的"就不把它當成有字符串起始意義的"。/表示不要把/后的"當成字符串的開始或者結尾為什么要有轉義符,就是要在程序中輸出回車等特殊的字符,不能直接在字符串中打回車,所以必須轉移。"/n"回車。string:"/"ab/""、"ab/nb"、"c://a.txt"、@"c:/a.txt"(推薦)。@表示字符串中的/不當成轉義符。@還可以定義多行文本。"http:////"得到的是兩個/"/""中/是告訴編譯器不要把這個"當成字符串的結束。@是不把/當成轉義符。@不是萬能的,不能解決字符串中有雙引號的問題,如果有雙引號還是用轉義符簡單的類型轉換:Convert.ToString()、ToString()、Convert.ToInt32() 。即可用中間變量,也可以不用。int i = Convert.ToInt32(Console.ReadLine());變量的命名規(guī)則:第一個字符必須是字母或者下劃線(_),其后的字符可以是任意個數(shù)字、字母、下劃線。不能全部使用C#的關鍵字,比如class、namespace、new、void等。判斷方式:VS中亮藍色的就是關鍵字

•相等判斷:==,不要和=混淆。WriteLine("{0}",i==1);WriteLine("{0}",i=1);的區(qū)別。Console.WriteLine("{0}",i=1);//C#中賦值表達式也有值,它的值表示為賦值后變量的值•不等判斷:!=•大小比較:<、>、<=、>=•取反:!•組合運算:&&(并且)、||(或者)。–&& 并且:只有兩邊都為true的時候,表達式的值才為true,否則是false;–||或者:兩邊只要有一個為true的時候,表達式的值就是true,否則是false;

程序代碼:

變量:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 變量{    class PRogram    {        static void Main(string[] args)        {            int a = 10;            a = 11;            Console.WriteLine(a);            string s = "朋友,你好!";            Console.WriteLine(s);            char c = 'a';            Console.WriteLine(c);            char c1 = '白';//在c# 里面漢字也表示一個字符            Console.WriteLine(c1);            bool b = true;            Console.WriteLine(b);//只有兩個取值 true ,false            //int 的最大值,最小值            Console.WriteLine("int的最大值{0},最小值{1}",int.MaxValue,int.MinValue);            Console.ReadKey();        }    }}
View Code

字符串

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 字符串1{    class Program    {        static void Main(string[] args)        {            //string name = "to/"m";//如果要輸出 to"m 則需要用到轉義字符 /表示不能把/ 后面的"看成開始或結束            //string name = "to/nm";            string name = "to//m";            //string s = "C://Intel//Logs";            string s = @"C:/Intel/Logs";            string s1 = @"sjdfjeojfla                     fpelpflep";//加上@聲明多行字符串            Console.WriteLine(name);            Console.WriteLine(s);            Console.WriteLine(s1);            //數(shù)據(jù)類型轉換            string s2 = "2345";            int a = Convert.ToInt32(s2);            int b = a + 20;            Console.WriteLine(b);            Console.ReadKey();        }    }}
View Code

數(shù)據(jù)類型轉換

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 數(shù)據(jù)類型轉換{    class Program    {        static void Main(string[] args)        {            Console.WriteLine("請輸入第一個數(shù)字:");            string num1 = Console.ReadLine();            Console.WriteLine("請輸入第二個數(shù):");            string num2 = Console.ReadLine();            //Console.WriteLine(num1+num2);//這里是把兩個字符串連接起來            int i1 = Convert.ToInt32(num1);            int i2 = Convert.ToInt32(num2);            Console.WriteLine(i1+i2);//轉換為int類型            Console.ReadKey();        }    }}
View Code

交換兩個變量的值

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 交換兩個變量的值{    class Program    {        static void Main(string[] args)        {            int a = 10;            int b = 20;            Console.WriteLine("a的值是{0},b的值是{1}", a, b);            int temp = a;            a = b;            b = temp;            Console.WriteLine("a的值是{0},b的值是{1}",a,b);            Console.ReadKey();        }    }}
View Code

布爾運算

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 布爾運算{    class Program    {        static void Main(string[] args)        {            int i = 5;            bool b=(i==9);//判斷i是否等于9,如果等于9則為true,否則為false                 b = (i != 9);//不等于                 b=(i>=9);//大于等于                 bool a = true;                 a = !a;            Console.WriteLine(b);            Console.WriteLine(a);            int i1 = 9;            int i2 = -9;            bool bool_1 = (i1 > 0 && i2 > 0);            bool bool_2 = (i1 > 0 || i2 > 0);            Console.WriteLine(bool_1);            Console.WriteLine(bool_2);            Console.ReadKey();        }    }}
View Code


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 西青区| 腾冲县| 东乡县| 东台市| 武功县| 闻喜县| 元江| 邮箱| 五常市| 衡东县| 贵州省| 务川| 山东| 平利县| 昆明市| 兴宁市| 蓬莱市| 清水河县| 东至县| 宁海县| 阳城县| 革吉县| 桃源县| 上高县| 大英县| 井陉县| 黄浦区| 古丈县| 石渠县| 长治县| 新巴尔虎右旗| 昭觉县| 郴州市| 繁峙县| 区。| 天镇县| 辉南县| 麻江县| 南涧| 登封市| 娄底市|