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 }

 

转载于:https://www.cnblogs.com/data1213/p/10706253.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值