0505.Net基础班第二天(基础语法)

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _13_转移符
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             //  Console.WriteLine("今天天气好晴\n朗处处好风光");
14 
15 
16             //Console.WriteLine("我想在这句话中输出一\"\"个英文半角的双引号");
17 
18             //string name1 = "张三";
19             //string name2 = "李思思";
20             //string name3 = "王小五";
21             //string name4 = "李狗蛋";
22             //Console.WriteLine("{0}\t{1}", name1, name2);                                                            
23             //Console.WriteLine("{0}\t{1}", name3, name4);
24 
25 
26             //Console.WriteLine("学习编\b程有用\b么?学了不一定会,会了不一定能找到工作,找到工作 不应能买的起房子,买的起房子不一定娶得起老婆,娶得起老婆不一定生的了孩子,生的了孩子不一定是你的\b");
27 
28             //Console.ReadKey();
29 
30 
31 
32             //string str = "今天天气好晴\r\n朗处处好风光";
33 
34             //System.IO.File.WriteAllText(@"C:\Users\SpringRain\Desktop\1111.txt", str);
35             //Console.WriteLine("写入成功!!!");
36             //Console.ReadKey();
37 
38 
39             //char c = '\b';//\ 在里面起到了一个转义的作用
40             //char cc='bb';
41 
42             //string path=@"F:\老赵生活\music\a\b\c\d\e\小泽玛利亚.avi";
43             //Console.WriteLine(path);
44             //Console.ReadKey();
45 
46 
47             Console.WriteLine(@"今天天气好晴
48 朗处处好风光");
49             Console.ReadKey();
50 
51         }
52     }
53 }

 

1、注释符 1)、注销 2)、解释

2、c#的3种注释符 1)、单行注释 // 2)、多行注释 /*要注释的内容*/ 3)、文档注释 /// 多用来解释类或者方法

3、变量 用来在计算机当中存储数据。

孙全 开房 火车 26小时  去旅馆睡觉 孙全  一个人  单人房  308 孙全 and  girl  双人间  一张床 521 孙全 and  boy  双人间 两张床  520

存储整数100 数据类型:整数 在内存中开辟的空间应该是整数类型 int

存储变量的语法: 变量类型 变量名; 变量名=值;

"="号:在这并不表示等于的意思,而是赋值的意思,表示把等号右边的值赋值给等号左边的变量。

声明并且给变量赋值的简写形式: 变量类型 变量名=值;

4、数据类型 1)、整数类型:int  只能存储整数,不能存储小数。 2)、小数类型:double 既能存储整数,也能存储小数,小数点后面的位数 15~16位。 3)、金钱类型:decimal:用来村粗金钱,值后面需要加上一个m. 4)、字符串类型:string,用来存储多个文本,也可以存储空,字符串类型的值需要被 双引号引来, 这个双引号必须是英文半角状态下的双引号 5)、字符类型:char,用来存储单个字符,最多、最少只能有一个字符,不能存储空。 字符类型的值需要用 单引号因起来。英文半角状态下的单引号。

5、波浪线 1)、如果你的代码中出现了红色的波浪线,意味着你的代码中出现了 语法错误。 2)、如果你的代码中出现了绿色的波浪线,说明你的代码语法并没有错误, 只不过提示你有可能会出现错误,但是不一定会出现错误。警告线

6、变量的使用规则 如果你要是用变量的话,应该要先声明再赋值再使用。

7、命名规则: ****首先要保证的就是这个变量的名字要有意义。 1 现阶段给变量起名字的时候都以字母开头 2 后面可以跟任意“字母”、数字、下划线. 注意: 1)你起的变量名不要与c#系统中的关键字重复. 2)在c#中,大小写是敏感的.  HTML 3)同一个变量名不允许重复定义(先这么认为,不严谨)

给变量起名字的时候要满足两个命名规范: 1、Camel 骆驼命名规范。要求变量名首单词的首字母要小写,其余每个单词的首字母要大写。 多用于给变量命名。 2、Pascal 命名规范:要求每个单词的首字母都要大写,其余字母小写。多用于给类或者方法命名。 HighSchoolStudent

highSchoolStudent

8、赋值运算符 =:表示赋值的意思,表示把等号右边的值,赋值给等号左边的变量。 由等号连接的表达式称之为赋值表达式。 注意:每个表达式我们都可以求解除一个定值,对于赋值表达式而言,等号左边的变量的值, 就是整个赋值表达式的值。 int number=10;

9、+号的作用 1)、连接:当+号两边有一边是字符串的时候,+号就起到连接的作用。 2)、相加:两边是数字的时候

10、占位符 使用方法:先挖个坑,再填个坑。 使用占位符需要注意的地方: 1、你挖了几个坑,就应该填几个坑,如果你多填了,没效果。                                  如果你少填了,抛异常。 2、输出顺序:按照挖坑的顺序输出。                 11、异常 异常是指:语法上并没有任何错误,只不过在程序运行的期间,由于某些原因出现了问题, 使程序不能再正常的运行。

12、转义符 转义符指的就是一个'\'+一个特殊的字符,组成了一个具有特殊意义的字符。 \n:表示换行 \":表示一个英文半角的双引号 \t:表示一个tab键的空格 \b:表示一个退格键,放到字符串的两边没有效果。 \r\n:windows操作系统不认识\n,只认识\r\n \\:表示一个\

@符号 1、取消\在字符串中的转义作用,使其单纯的表示为一个'\' 2、将字符串按照编辑的原格式输出

13、算数运算符 + - * / %

14、类型转换 隐式类型转换: 我们要求等号两遍参与运算的操作数的类型必须一致,如果不一致,满足下列条件会发生 自动类型转换,或者称之为隐式类型转换。 两种类型兼容 例如:int 和 double 兼容(都是数字类型) 目标类型大于源类型 例如:double > int   小的转大的

显示类型转换: 1、两种类型相兼容  int--double 2、大的转成小的  double----int 语法: (待转换的类型)要转换的值;

总结: 自动类型转换:int---->double 显示类型转换:double--->int

20平 20平 4  5平 

 

01注释符的使用

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _01注释符的使用
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13 
14             //这行代码的作用是将Hello World打印到控制台当中
15           //  Console.WriteLine("Hello World");
16 
17             //这行代码的作用是暂停当前这个程序
18            // Console.ReadKey();
19 
20 
21 
22             /*
23             Console.WriteLine("Hello World");
24             Console.WriteLine("Hello World");
25             Console.WriteLine("Hello World");
26             Console.WriteLine("Hello World");
27             Console.WriteLine("Hello World");
28             Console.WriteLine("Hello World");
29             Console.WriteLine("Hello World");
30             Console.WriteLine("Hello World");*/
31 
32         }
33 
34 
35 
36         /// <summary>
37         /// 这个方法的作用就是求两个整数之间的最大值
38         /// </summary>
39         /// <param name="n1">第一个整数</param>
40         /// <param name="n2">第二个整数</param>
41         /// <returns>返回比较大的那个数字</returns>
42         public static int GetMax(int n1, int n2)
43         {
44             return n1 > n2 ? n1 : n2;
45         }
46     }
47 
48 
49 
50     /// <summary>
51     /// 这个类用来描述一个人的信息 从 姓名 性别 年龄描述
52     /// </summary>
53     public class Person
54     {
55         public string Name
56         { 
57             get;
58             set;
59         }
60 
61         public int Age
62         {
63             get;
64             set;
65         }
66 
67         public char Gender
68         {
69             get;
70             set;
71         }
72     }
73 
74 }
View Code

02VS当中的常用快捷键

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _02VS当中的常用快捷键
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             #region 这些代码实现了XX功能
14             Console.WriteLine("fdsfdsf");
15             Console.WriteLine("fdsfdsf");
16             Console.WriteLine("fdsfdsf");
17             Console.WriteLine("fdsfdsf");
18             Console.WriteLine("fdsfdsf");
19             Console.WriteLine("fdsfdsf");
20             Console.WriteLine("fdsfdsf");
21             Console.WriteLine("fdsfdsf");
22             Console.WriteLine("fdsfdsf");
23             Console.WriteLine("fdsfdsf");
24             Console.WriteLine("fdsfdsf");
25             Console.WriteLine("fdsfdsf");
26             Console.WriteLine("fdsfdsf");
27             Console.WriteLine("fdsfdsf");
28             Console.WriteLine("fdsfdsf");
29             Console.WriteLine("fdsfdsf");
30             Console.WriteLine("fdsfdsf");
31             Console.WriteLine("fdsfdsf");
32             Console.WriteLine("fdsfdsf");
33             Console.WriteLine("fdsfdsf");
34             Console.WriteLine("fdsfdsf");
35 
36             #endregion
37         }
38     }
39 }
View Code

03、变量

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _03_变量
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             //变量类型 变量名;
14             // 变量名 = 值;
15             //100
16 
17             ////官方语言:声明或者定义了一个int类型的变量
18             //int number;//在内存中开辟了一块能够存储整数的空间
19             ////官方语言:给这个变量进行赋值
20             //number = 100;//表示把100存储到了这块空间内
21 
22 
23             //int n = 3.14;
24 
25 
26           //  double d = 3;
27 
28             //张三 李四 王五 赵六 abcdefg
29 
30             //string zsName = "张三";
31             //string s="";//字符串可以存储 空
32 
33             ////字符串 字符  羊肉串和羊肉 
34             //char gender = '男女';
35            // char c='';
36 
37 
38             //decimal money = 5000m;
39 
40             double d = 36.6;
41             Console.WriteLine(d);
42             Console.ReadKey();
43         }
44     }
45 }
View Code

04变量的使用规则

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _04变量的使用规则
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13            int number;//声明或者定义了整数类型的变量
14             number = 20;
15            // Console.WriteLine(number);
16             Console.ReadKey();
17 
18            // String s = "颤三";
19             string ss = "李四";
20            
21         }
22     }
23 }
View Code

05变量的命名规范

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _05变量的命名规范
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             //int number_1 = 10;
14             //int number_2 = 20;
15 
16             //int number = 10;
17             //int Number = 10;
18 
19 
20             int number;
21           //  int  number = 10;
22            // int string=10;
23             //int a = 10;
24             //int b = 20;
25         }
26     }
27 }
View Code

06赋值运算符

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _06赋值运算符
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             int n = 10;
14             n = 50;//重新赋值,一旦给一个变量重新赋值,那么老值就不存在了,取而代之的新值。
15             Console.WriteLine(n);
16             Console.ReadKey();
17         }
18     }
19 }
View Code

07+号的使用

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _07_号的使用
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             //string name = "王五";
14             //Console.WriteLine("你好,"+name);
15 
16             Console.WriteLine(5 + "5");
17             Console.ReadKey();
18         }
19     }
20 }
View Code

08两个练习

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _08两个练习
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             //有个叫卡卡西的人在旅店登记的时候前台让他填一张表,
14             //这张表的里的内容要存到电脑上,
15             //有姓名、年龄、邮箱、家庭住址,工资.
16             //之后把这些信息显示出来
17             //string name = "卡卡西";
18             //int age = 30;
19             //string email = "kakaxi@qq.com";
20             //string address = "火影村";
21             //decimal salary = 5000m;
22 
23             //Console.WriteLine("我叫{0},我今年{1}岁了,我住在{2},我的邮箱是{3},我的工资是{4}", name, age, address, email, salary);
24 
25 
26             //Console.WriteLine("我叫" + name + ",我住在" + address + ",我今年" + age + "岁了" + ",我的邮箱是" + email + ",我的工资是" + salary);
27             //Console.ReadKey();
28 
29 
30             //int age = 18;
31             //age = 81;
32             //Console.WriteLine("原来你都" + age + "岁了呀");
33             //Console.ReadKey();
34 
35 
36             //3.定义四个变量,分别存储一个人的姓名、性别(Gender)、年龄、电话
37             //(TelephoneNumber)。然后打印在屏幕上 (我叫X,我今年 X岁了,我是X生,
38             //我的电话是XX)(电话号用什么类型,如:010-12345)
39             string name = "张三";
40             char gender = '';
41             int age = 18;
42             string tel = "12345678900";
43             Console.WriteLine("我叫{0},我今年{1}岁了,我是{2}生,我的电话是{3}", name, age, gender, tel);
44             Console.ReadKey();
45 
46 
47         }
48     }
49 }
View Code

09下午复习

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _09下午复习
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             /*
14              变量:存储数据
15              * 赋值运算符
16              * 数据类型:
17              * int 整数
18              * double decimal string char 
19              * 命名规范
20              * Camel:
21              * Pascal
22              * 注释:
23              * //
24              * 
25              ///
26              * +号
27              */
28         }
29     }
30 }
View Code

10占位符

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _09下午复习
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             /*
14              变量:存储数据
15              * 赋值运算符
16              * 数据类型:
17              * int 整数
18              * double decimal string char 
19              * 命名规范
20              * Camel:
21              * Pascal
22              * 注释:
23              * //
24              * 
25              ///
26              * +号
27              */
28         }
29     }
30 }
View Code

11交换变量

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _11交换变量
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             //int n1 = 10;
14             //int n2 = 20;
15 
16             //int temp = n1;
17             //n1 = n2;
18             //n2 = temp;
19 
20 
21             //Console.WriteLine("交换后,n1的值是{0},n2的值是{1}", n1, n2);
22             //Console.ReadKey();
23 
24             //请交换两个int类型的变量,要求:不使用第三方的变量
25             int n1 = 50;
26             int n2 = 30;
27             //n1=20  n2=10;
28 
29             n1 = n1 - n2;//n1=-10 n2=20
30             n2 = n1 + n2;//n1=-10 n2=10
31             n1 = n2 - n1;
32             Console.WriteLine("交换后,n1的值是{0},n2的值是{1}", n1, n2);
33             Console.ReadKey();
34         }
35     }
36 }
View Code

12接收用户的输入

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _12接收用户的输入
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             //Console.WriteLine("请输入你的姓名");
14             ////我们还想要接收你输入的姓名
15             ////接收用户在控制台的输入  11  3.14  男  张三
16             //string name = Console.ReadLine();
17 
18             //Console.WriteLine("您的姓名是{0}", name);
19             //Console.ReadKey();
20 
21             //1.练习:问用户喜欢吃什么水果(fruits),假如用户输入”苹果”,则显示”哈哈,这么巧,我也喜欢吃苹果”
22             //Console.WriteLine("美女,你喜欢吃啥子水果哟~~~~");
23             //string fruit = Console.ReadLine();
24             //Console.WriteLine("这么巧呀,我也喜欢吃{0}", fruit);
25             //Console.ReadKey();
26 
27             //2.练习:请用户输入姓名性别年龄,当用户按下某个键子后在屏幕上显示:您好:XX您的年龄是XX是个X生
28             //Console.WriteLine("请输入您的姓名");
29             //string name = Console.ReadLine();
30 
31             //Console.WriteLine("请输入您的年龄");
32             //string age = Console.ReadLine();
33 
34 
35             //Console.WriteLine("请输入您的性别");
36             //string gender = Console.ReadLine();
37 
38             //Console.WriteLine("{0}你的年龄是{1}是个{2}生",name,age,gender);
39             //Console.ReadKey();
40 
41         }
42     }
43 }
View Code

13、转移符

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _13_转移符
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             //  Console.WriteLine("今天天气好晴\n朗处处好风光");
14 
15 
16             //Console.WriteLine("我想在这句话中输出一\"\"个英文半角的双引号");
17 
18             //string name1 = "张三";
19             //string name2 = "李思思";
20             //string name3 = "王小五";
21             //string name4 = "李狗蛋";
22             //Console.WriteLine("{0}\t{1}", name1, name2);                                                            
23             //Console.WriteLine("{0}\t{1}", name3, name4);
24 
25 
26             //Console.WriteLine("学习编\b程有用\b么?学了不一定会,会了不一定能找到工作,找到工作 不应能买的起房子,买的起房子不一定娶得起老婆,娶得起老婆不一定生的了孩子,生的了孩子不一定是你的\b");
27 
28             //Console.ReadKey();
29 
30 
31 
32             //string str = "今天天气好晴\r\n朗处处好风光";
33 
34             //System.IO.File.WriteAllText(@"C:\Users\SpringRain\Desktop\1111.txt", str);
35             //Console.WriteLine("写入成功!!!");
36             //Console.ReadKey();
37 
38 
39             //char c = '\b';//\ 在里面起到了一个转义的作用
40             //char cc='bb';
41 
42             //string path=@"F:\老赵生活\music\a\b\c\d\e\小泽玛利亚.avi";
43             //Console.WriteLine(path);
44             //Console.ReadKey();
45 
46 
47             Console.WriteLine(@"今天天气好晴
48 朗处处好风光");
49             Console.ReadKey();
50 
51         }
52     }
53 }
View Code

14、算数运算符

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _14_算数运算符
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             //int n1 = 10;
14             //int n2 = 3;
15             //int result = n1 / n2;
16             ////Console.WriteLine(result);
17             ////Console.ReadKey();
18 
19             ////演示:某学生三门课成绩为,语文:90  数学:80  英语:67,编程求总分和平均分.
20             //int chinese = 90;
21             //int math = 80;
22             //int english = 67;
23             //Console.WriteLine("总成绩是{0},平均成绩是{1}", chinese + math + english, (chinese + math + english) / 3);
24             //Console.ReadKey();
25 
26 
27             //练习2:计算半径为5的圆的面积和周长并打印出来.(pi为3.14)面积:pi*r*r; Perimeter(周长)
28 
29             //=号两遍的数据类型必须一样
30             //int r = 5;
31             //double area = 3.14 * r * r;
32             //double perimeter = 2 * 3.14 * r;
33             //Console.WriteLine("圆的面积是{0},周长是{1}", area, perimeter);
34             //Console.ReadKey();
35 
36 
37             //练习3:某商店T恤(T-shirt)的价格为35元/件,
38             //裤子(trousers)的价格为120元/条.小明在该店买了3件T恤和2条裤子,
39             //请计算并显示小明应该付多少钱?
40 
41 
42             //int T_shirt = 35;
43             //int trousers = 120;
44             //int totalMoney = 3 * T_shirt + 2 * trousers;
45             //Console.WriteLine(totalMoney);
46 
47             //double realMoney = totalMoney * 0.88;
48             //Console.WriteLine(realMoney);
49 
50             //Console.ReadKey();
51             ////打8.8折后呢?
52 
53             //int number = 10;
54             //int---double
55             //double d = number;//自动类型转换 隐式类型转换   int--double
56 
57             //double d = 303.6;
58             ////语法:
59             ////(待转换的类型)要转换的值;
60             ////double----int//强制类型转换  显示类型转换
61             //int n = (int)d;
62             //Console.WriteLine(n);
63             //Console.ReadKey();
64         }
65     }
66 }
View Code

15、类型转换

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace _15_类型转换
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             int n1 = 10;
14             int n2 = 3;
15             double d = n1*1.0 / n2;
16             Console.WriteLine("{0:0.0000}",d);
17             Console.ReadKey();
18 
19 
20             ////int n1 = 5;
21             //double n1 = 5;
22             //int n2 = 2;
23             //double d = n1 / n2;
24             //Console.WriteLine(d);
25             //Console.ReadKey();
26         }
27     }
28 }
View Code

 

转载于:https://www.cnblogs.com/liuslayer/p/4713258.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值