There have been times when there was a need to use the C# keywords as names of the variable, but we were not able to do so as it is not allowed and gives a Compile Time error.
For e.g. the below code, will give you a compile time error stating: "Cannot implicitly convert type 'System.Random' to 'string'"
- Random string = new Random();
It is simply because the name used "string" is in itself a keyword and therefore .net interprets it in a way that we are trying to convert the type Random to string.
Although, there is a way in which we can use this name without any error. Please see the below code:
- Random @string = new Random();
By using the '@", it is now stated that it is a variable now and is no longer considered as a keyword.
The same thing can be used for other keywords as well.
Please feel free to post your inputs as comments.
Thanks
Vipul