Is there a way in C# to disable keyword's functionality in code? In my case I want to define one of my enum items as float which obviously makes Visual Studio a bit confused :)
public enum ValidationType
{
email,
number,
float,
range
}
Technically, you can do it like that:
public enum ValidationType
{
email,
number,
@float, // note "@" before "float"
range
}
however, even if it's possible to use key words as ordinal identifiers it's not a good practice. Probably a better solution in your case is to capitalize:
public enum ValidationType
{
Email,
Number,
Float,
Range
}
No. Keywords are predefined, reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @
as a prefix.
For example:
@if
is a valid identifier butif
is not because if
is a keyword.https://msdn.microsoft.com/en-us/library/x53a06bb.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With