Quick Tip: Use nameof() to Avoid Magic Strings
Instead of hard-coding strings when referring to variables or properties, use nameof() to make your code safer and easier to maintain:
Console.WriteLine("Score"); // Bad
Console.WriteLine(nameof(Score)); // Good
If you rename the property, the compiler will catch it — no more silent runtime bugs.
Have you used nameof() in your projects yet?
0
0 comments
Anthony Grotte
1
Quick Tip: Use nameof() to Avoid Magic Strings
powered by
Syntactic Sugar Shack: C#
skool.com/syntactic-sugar-shack-7269
Learn and master C# with coding challenges, tutorials, and a supportive developer community.
Build your own community
Bring people together around your passion and get paid.
Powered by