Windows Phone Developers

Showing posts with label 'keyword' is a keyword - Compiler Error CS1041. Show all posts
Showing posts with label 'keyword' is a keyword - Compiler Error CS1041. Show all posts

Tuesday, December 16, 2008

How to use Reserved Words in .NET (C#)

How to use Keywords in .NET (C#)

If you can use tens and thousands of words as identifier, why should one use the few keywords reserved by C#?

private static void KeywordExample()

{

string string = "Some String";

}

Might be you still want to use ‘bool’, ‘string’ etc. But using this will throw “identifier expected, 'keyword' is a keyword - Compiler Error CS1041”

A reserved word for the C# language was found where an identifier was expected. Replace the keyword with a user-specified identifier.

To overcome this error, prefix the identifier with “@”. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier.

private static void KeywordExample()

{

string @string = "Some String";

Console.Write(@string);

}

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon