I am trying to follow some tutorials for ASP.Net and for the life of me, I just can't figure out what the @
Symbol does when it is before an variable.
I thought it was just a shortcut to either session variables or request.form, but I have tried it in a few places without any luck.
When I put it in somewhere at random, I get the error : Expression Expected
, however, when I look at the examples I am working from, they do not look like expressions so I am very confused!
Please help!?
The @
symbol in C# allows you to use a keyword as a variable name.
For instance:
//this will throw an exception, in C# class is a keyword
string class = "CSS class name";
//this won't
string @class = "CSS class name";
Usually it's best to avoid using keywords as variable names, but sometimes it's more elegant than having awkward variable names. You tend to most often see them when serialising stuff for the web and in anon types.
Your error is probably due to applying the @
before a variable name that isn't a keyword.
Update:
In T-SQL @
is always used before parameter names, for instance:
select *
from [mytable]
where [mytable].[recId] = @id
You would then specify the @id parameter when you called the query.
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