In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Many beginners are not very clear about the role of @ logo in c#. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
1. Add @ before the variable name to tell the compiler that @ is followed by the variable name. It is mainly used when the variable name and C# keyword are repeated.
String [] @ for = {"John", "James", "Joan", "Jamie"}; for (int ctr = 0; ctr < @ for.Length; ctr++) {Console.WriteLine ($"Here is your gift, {@ forctr]}!");} / / The example displays the following output:// Here is your gift, John for.Length; ctr++ / Here is your gift, James for.Length; ctr++ / Here is your gift, The example displays the following output:// Here is your gift / Here is your gift, Jamie!
2. add @ before the string, and the escaped string in the string will no longer be escaped. Exception: "will still be escaped as", {{and}} will still be escaped as {and}. When using both string interpolation and verbatim strings, $comes before @
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. Similar to the first article, it is used to distinguish between two property names in case of naming conflicts. The name of the type customized by the attribute Attribute should end with Attribute, such as InfoAttribute, which we can reference later with InfoAttribute or Info. But if we define two custom features named Info and InfoAttribute, the compiler won't know which one when using the name Info. At this point, if you want to use Info, use @ Info, and if you want to use InfoAttribute, write your name in full.
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 () {}} is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.