C#中“@”的作用和用法

来源:互联网 发布:网络延长器品牌 编辑:程序博客网 时间:2024/05/21 04:23
“@”在看别人程序的时候偶尔看到,总结了一下两个用途

1. 不常用,也不推介用的用法。 @关键字 可以作为标识符来使用,说白了,就是讲关键字变成非关键字。

2.逐字字符串字面量,以@开头,后面是由引导包含的字符串。使用引导号暴扣的字符串的内容原样输出,而且他们能够跨越两行或更多行。因此,可以加入新行,制表符等,而不需要使用转义序列。唯一例外的情况是,为了显示双引号("),必须在同一行中使用两个双引号(“”)。下面的程序演示了逐字字符串字面量的使用:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;namespace cxx{    class test    {        static void Main(string[] args)        {            Console.WriteLine(            @"this is a verbatim             string literal that spans             serval lines.            my name is shoneworn.");            Console.WriteLine(@"my name is :""shoneworn""");            Console.ReadKey();        }    }}

 

运行效果如下:

0 0
原创粉丝点击