Strange but true: using a keyword as a variable

Can you use a keyword as an argument, or any other kind of local variable? Why would you want to do that? That aside: how?

Easy! Just use the @ in front of any keyword and you can now use it as a variable. For example:

class Program

{

  static void UsingKeywordArg(string @string)

  {

    Console.WriteLine(@string);

  }

 

  static void Main(string[] args)

  {

    UsingKeywordArg("Hello world");

  }

}

 

I found this while digging through some generated code from workflow foundation 4. Cool!

  • colon cleaner

    2/9/2010 9:09:21 AM |

    Whenever an individual or a business decides that success has been attained, progress stops.

Loading