C # prefix parameter names with @

Possible duplicate:
What does the @ symbol mean before a variable name in C #?

Duplicate:

What does the @ symbol mean before a variable name in C #?

Sometimes I see some C # code where the method parameter has the @ prefix, for example:

public static void SomeStaticMethod( SomeType @parameterName ) { } 

What is the meaning of this? Is it of any importance?

I create an EventListener in NHibernate, and when I allow VS.NET to generate interface methods, it generates the OnPostLoad method as follows:

  public class PostLoadEventListener : IPostLoadEventListener { public void OnPostLoad( PostLoadEvent @event ) { } } 

Why is this?

+46
c #
Jun 24 '09 at 14:19
source share
3 answers

Try creating a variable called class and see what happens - you will notice that you receive an error message.

This allows you to use reserved words as variable names.

Unconnected, you will also notice lines with the @ prefix as well - these are not the same thing ...

 string says = @"He said ""This literal string lets me use \ normally and even line breaks""."; 

This allows you to use the "literal" value of the string, that is, you can have new lines or characters without screens, etc.

+73
Jun 24 '09 at 14:20
source share

The @ prefix allows you to use reserved words, such as class, interface, events, etc. like variable names in C #. So you can do

 int @int = 1 
+22
Jun 24 '09 at 14:21
source share
Event

is the C # keyword, the @ character is an escape character that allows you to use the keyword as a variable name.

+16
Jun 24 '09 at 14:21
source share



All Articles