What are the ~
and @
characters in the path string in ASP.NET. Example:
StreamReader srFile = new StreamReader(@"\server\pasta\arquivo.html");
What are the ~
and @
characters in the path string in ASP.NET. Example:
StreamReader srFile = new StreamReader(@"\server\pasta\arquivo.html");
In ASP.NET path you have some 'shortcuts' to specify the path.
Let's assume your project is on the following path
C:\Projetos\TestandoOPath
And you will use the code on the page that is in http://localhost:<porta>/TestandoOPath/Pagina/Teste/index.aspx
You can use the following options:
C:\Projetos\TestandoOPath\Pagina\Teste
C:\Projetos\TestandoOPath\Pagina
C:\Projetos\TestandoOPath
And the use of @
is to treat text without the escape character effect .
Example: new StreamReader(@"\server\pasta\arquivo.html");
if you do not put @
you need to put another \
getting "\server\pasta\arquivo.html"
to null the escape effect of it.
More information about 'shortcuts' in the path can be seen here in English OS .
The symbol @
, before a literal string, serves to avoid escaping the special characters of the string.
@"\server\pasta\arquivo.html"
is equivalent to:
"\server\pasta\arquivo.html"
The @
symbol can also be used to use keywords as variable names:
int class; //erro de compilação, a palavra "class" esta reservada
int @class; //funciona
The ~
operator is the complement of a (or bitwise negation). Serves to deny all bits.
~ 1001 = 0110