Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to escape key words in c#?

Tags:

c#

vb.net

lambda

I want to do the equivalent of the following VB in c#

Function([class]) "hello"

This would be the same as this in c#

class=>"hello"

The problem is that the word class is a key word in the language. But I want to use it as a variable name. In the VB example you can use the [] brackets to 'escape' that key word and allow it to be used as a variable name.

Is there a way to do this in C# ?

like image 281
7wp Avatar asked Apr 06 '10 20:04

7wp


2 Answers

You need to add @ to variable names:

@class

But it is a very bad practice. Every time you name your variable as a keyword a kitten dies :)

like image 171
Andrew Bezzub Avatar answered Sep 21 '22 20:09

Andrew Bezzub


Use @ for reserved words:

@class=>"hello"
like image 45
Darin Dimitrov Avatar answered Sep 20 '22 20:09

Darin Dimitrov