views:

27

answers:

2

Hi,

In a sample use of the BeginInvoke thread pool method:

...
Func<string, int> method = someWorkMethod;
IAsyncResult cookie = method.BeginInvoke("test", ...

One of the expected parameters (the last one), in BeginInvoke is:

object @object

What does the @ signify ?

Thanks,

Scott

+3  A: 

The @ is an escape symbol that lets you use keywords as symbol names. For instance, you couldn't normally do:

object object = something;

...because object is a keyword, but you can do:

object @object = 

void DoSomething(params object[] @params) {

...etc

Matthew Abbott
Ah, interesting! I had completely forgotton about that. Next question - why would I want to introduce possible confusion by using a reserved word or is it the framework just being as accomodating as possible ?
Scott Davies
Well, the feature is there for you to use it, whether you do or not, that's up to you. They allow it because sometimes keywords are using perfectly usable descriptions which could also be used for variable names. Sometimes it's frowned upon because they essentially read like keywords, so you've got to decide whether using them is worth the confusion?I use them on occasion, it does confuse the hell out of some :)
Matthew Abbott
@Scott: It also is there because the .NET framework is usable by other languages, some of which may have different reserved words... ("object" is not a keyword in all .net languages)
Reed Copsey
@Matthew: Good point. @Reed: I hadn't thought of languages outside of c# - another good point. Thanks guys!
Scott Davies
+1  A: 

It simply an escape character. That way, you're allowed to name parameters anything you want, even if it is a reserved keyword.

Philippe Leybaert