EloiStree / HelloSharpForUnity3D

Here we are going to check all the basic need to work in Unity3D with C#
0 stars 0 forks source link

Topic: use @"" #405

Open EloiStree opened 1 month ago

EloiStree commented 1 month ago

🤖 In C#, the @ symbol can be used in various contexts, but one of its common uses is to define a verbatim string literal. A verbatim string literal ignores escape sequences (like \n for a new line) and allows the string to span multiple lines. It's especially useful when dealing with file paths or regular expressions where backslashes are common.

Example 1: Verbatim String for File Path

string filePath = @"C:\Users\YourName\Documents\file.txt";

In this example, you don't need to escape the backslashes (\) in the file path.

Example 2: Multi-line String

string multiLineString = @"This is a multi-line string.
It can span multiple lines.
You don't need to use \n for new lines.";

Here, the string spans multiple lines without needing explicit new line characters (\n).

Example 3: Using @ with Reserved Keywords

You can also use the @ symbol to use reserved keywords as identifiers:

int @class = 10;
Console.WriteLine(@class);

In this case, class is a reserved keyword in C#, but by prefixing it with @, you can use it as a variable name.

These are some typical scenarios where the @ symbol is used in C#.