Home > Article > Backend Development > What does @ mean in c#
The @ symbol in C# cancels the escaped meaning of special characters, allowing strings to span multiple lines, Enum members to customize the underlying value, and to indicate that a method or property is asynchronous. The @ symbol in
c# The @ symbol in
c# is a modifier used to unescape The special meaning of the sequence.
Function
String
The following are examples of strings with and without the @ symbol:
<code class="c#">// 不带 @ 符号 string s = "Hello\nWorld!"; // 带 @ 符号 string s = @"Hello World!";</code>
In the first example , \n generates a newline character. But in the second example, \n is output as is due to the presence of the @ symbol.
Enum
Here are examples of Enum with and without the @ symbol:
<code class="c#">// 不带 @ 符号 enum Weekdays { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } // 带 @ 符号 enum Weekdays { Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6, Sunday = 7 }</code>
In the first example, the underlying Weekdays Values are integers starting from 0. But in the second example, the @ symbol allows specifying custom values for the Enum members.
Asynchronous methods and properties
The following are examples of asynchronous methods and properties with and without the @ symbol:
<code class="c#">// 不带 @ 符号 Task<int> GetNumber() { ... } // 带 @ 符号 Task<int> GetNumberAsync() { ... }</code>
In the first In the example, GetNumber is a synchronous method. In the second example, the @ symbol indicates that GetNumberAsync is an asynchronous method.
The above is the detailed content of What does @ mean in c#. For more information, please follow other related articles on the PHP Chinese website!