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 }

 

猜你喜欢

转载自www.cnblogs.com/data1213/p/10706253.html