ASP.Net @ Character

I'm trying to follow some tutorials for ASP.Net and for life, I just can't figure out what the @ symbol does when it is in front of the variable.

I thought it was just a shortcut to session variables or request.form, but I tried it in several places with no luck.

When I put it somewhere in random order, I get the error message: Expression Expected , however, when I look at the examples I work with, they do not look like expressions, so I'm very confused!

Please, help!?

+7
source share
3 answers

The @ symbol in C # allows you to use the keyword as a variable name.

For example:

 //this will throw an exception, in C# class is a keyword string class = "CSS class name"; //this won't string @class = "CSS class name"; 

It is usually better to avoid using keywords as variable names, but sometimes it is more elegant than the names of inconvenient variables. You, as a rule, most often see them when serializing material for the Internet and in the form of announcements.

Your error is probably related to using @ in front of a variable name that is not a keyword.

Update:

In T-SQL, @ always used before parameter names, for example:

 select * from [mytable] where [mytable].[recId] = @id 

Then you specify the @id parameter when calling the request.

+8
source share

There are several different uses for the @ symbol, depending on where it is located.

Before the variable name, it allows you to use the reserved word as the variable name:

 string @string = "a string variable named string"; 

This is not a good practice, as it can be very confusing when reading code.

Before a string, it is called a string literal and means that you do not need to hide slashes and such:

 string path = @"c:\my path\is here"; string normal_path = "c:\\my path\\is here"; 
+7
source share

An ASPX page uses the @ symbol along with pointers on the page.

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

The code page uses the @Symbol character for character characters in a string.

 String s = @"c:/Document/Files/Sample.txt" 
+5
source share

All Articles