C#入门课程之基础认识

命名规则:

注意变量名的第一个字符必须是字母、下划线、以及@字符

 

字面值:

字符串字面值:

用Unicode表示一个字符方式:\uxxxx,其中xxxx表示4位的十六进制数,下面两种表示方式一致:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApp1
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             string s1 = "beijing\'s spring";
14             Console.WriteLine(s1);
15 
16             string s2 = "beijing\u0027s spring";
17             Console.WriteLine(s2);
18         }
19     }
20 }

 一字不差字符串字面值:

在字符串前添加@字符,那么这个字符串本身所有内容都当做字符串一字不差的内容,即不会发生转义。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApp1
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             string s1 = "beijing\'s spring \n"+
14                 "贼冷";
15             Console.WriteLine(s1);
16 
17             string s2 = @"beijing's spring
18  贼冷";  //不能有缩进,否则有多少个空格都是会被识别为s2字符串本身,这里故意缩进一个空格
19             Console.WriteLine(s2);
20 
21             string s3 = "c:\\system(32)\\leanote\\";
22             Console.WriteLine(s3);
23 
24             string s4 = @"c:\system(32)\leanote\";
25             Console.WriteLine(s4);
26 
27             int a = 1;
28         }
29     }
30 }

 

 

命名空间:

 1 using System; //是.Net Fromework应用程序的根命名空间,包含了控制台应用程序的必要功能。
 2 namespace ConsoleApp1  //定义本程序的命名空间
 3 {
 4     class Program
 5     {
 6         static void Main(string[] args)
 7         {
 8             string s1 = @"c:\system(32)\leanote\";
 9             Console.WriteLine(s1);   // Console就是 System中定义的一个静态类
10 
11             int a = 1;
12         }
13     }
14 }

using 还可以将静态成员直接包含到作用域中:

 1 using static System.Console;
 2 namespace ConsoleApp1  //定义本程序的命名空间
 3 {
 4     class Program
 5     {
 6         static void Main(string[] args)
 7         {
 8             string s1 = @"c:\system(32)\leanote\";
 9             WriteLine(s1);   //不用再指明Console类名
10 
11             int a = 1;
12         }
13     }
14 }

 

posted @ 2019-04-14 18:02  e-data  阅读(334)  评论(0编辑  收藏  举报