In C# use the nameof() expression so your property, class and namespace references are type safe

In C# if you’re referencing property, class or namespace names in your code use the nameof() expression rather than strings so your references are type safe

If you have string literals containing property, class and namespace names all around your code you have to maintain them manually. If you rename a class which is referenced from a string you have to remember to change the value of the string too but if you use nameof() this is done automatically by your IDE.

Leave a Reply

Your email address will not be published. Required fields are marked *