I read some C# article to combine a path using Path.Combine
(part1,part2).
It uses the following:
string part1 = @"c:\temp"; string part2 = @"assembly.txt";
May I know what is the use of @
in part1 and part2?
String literals are convertible and assignable to non-const char* or wchar_t* in order to be compatible with C, where string literals are of types char[N] and wchar_t[N]. Such implicit conversion is deprecated.
In practice, a string literal lets you set specific strings as a type. In the example above, I have a person interface with a name , age , and mood . Name and age use prototypes, but mood uses a string literal. The syntax for creating string literals is similar to union types.
In this article The @ character prefixes a code element that the compiler is to interpret as an identifier rather than a C# keyword. The following example uses the @ character to define an identifier named for that it uses in a for loop. C# Copy.
@
is not related to any method.
It means that you don't need to escape special characters in the string following to the symbol:
@"c:\temp"
is equal to
"c:\\temp"
Such string is called 'verbatim' or @-quoted. See MSDN.
As other have said its one way so that you don't need to escape special characters and very useful in specifying file paths.
string s1 =@"C:\MyFolder\Blue.jpg";
One more usage is when you have large strings and want it to be displayed across multiple lines rather than a long one.
string s2 =@"This could be very large string something like a Select query which you would want to be shown spanning across multiple lines rather than scrolling to the right and see what it all reads up";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With