网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

c#中@标志的作用是什么

c#中@标志的作用是什么,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

创新互联建站是一家专注于成都网站设计、网站制作和遂宁联通机房的网络公司,有着丰富的建站经验和案例。

1、在变量名前加@,可以告诉编译器,@后的就是变量名。主要用于变量名和C#关键字重复时使用。

string[] @for = { "John", "James", "Joan", "Jamie" };for (int ctr = 0; ctr < @for.Length; ctr++){   Console.WriteLine($"Here is your gift, {@for[ctr]}!");}// The example displays the following output://     Here is your gift, John!//     Here is your gift, James!//     Here is your gift, Joan!//     Here is your gift, Jamie!

2、在字符串前加@,字符串中的转义字符串将不再转义。例外:""仍将转义为",{{和}}仍将转义为{和}。在同时使用字符串内插和逐字字符串时,$要在@的前面

string filename1 = @"c:\documents\files\u0066.txt";string filename2 = "c:\\documents\\files\\u0066.txt";
Console.WriteLine(filename1);Console.WriteLine(filename2);// The example displays the following output://     c:\documents\files\u0066.txt//     c:\documents\files\u0066.txt

3、类似于第一条,用于在命名冲突时区分两个特性名。特性Attribute自定义的类型名称在起名时应以Attribute结尾,例如InfoAttribute,之后我们可以用InfoAttribute或Info来引用它。但是如果我们定义了两个自定义特性,分别命名Info和InfoAttribute,则在使用Info这个名字时,编译器就不知道是哪个了。这时,如果想用Info,就用@Info,想用InfoAttribute,就把名字写全。

using System;
[AttributeUsage(AttributeTargets.Class)]public class Info : Attribute{   private string information;     public Info(string info)   {      information = info;   }}
[AttributeUsage(AttributeTargets.Method)]public class InfoAttribute : Attribute{   private string information;     public InfoAttribute(string info)   {      information = info;   }}
[Info("A simple executable.")] // Generates compiler error CS1614. Ambiguous Info and InfoAttribute. // Prepend '@' to select 'Info'. Specify the full name 'InfoAttribute' to select it.public class Example{   [InfoAttribute("The entry point.")]   public static void Main()   {   }}

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。


分享标题:c#中@标志的作用是什么
文章出自:http://bjjierui.cn/article/ihggdp.html

其他资讯