How do you use this @ in C #?

simpleSound = new SoundPlayer(@"c:\Windows\Media\chimes.wav");

Why and what is @ needed for?

+3
source share
7 answers

This is a literal string. Instead of escaping "\" by putting two of them "\", the compiler interprets the string "as is".

Suppose you want to print the following text on the screen: "Hello \t world".

If you just need to do Console.WriteLine("Hello \t world"), then your result will be as follows:

Hello    world

pay attention to the tab. This is because \ t is in tab form. However, if you use a literal, for example:

Console.WriteLine(@"Hello \t world")

then your result will be as follows:

"Hello \t world"
+8
source

. \, " .. escape-.

+3

@ , (, ).

+2

. \ , .

+2

"c:\\my\\file.txt" @"c:\my\file.txt"

, \n \t - .

0

@ , , ( ). :

public int @object = 1;
0

Defining the @ character before assigning a string value will prevent the need to double backslash (\) in C #. The at (@) character simply ignores escape characters.

0
source

Source: https://habr.com/ru/post/1779530/


All Articles