code4it-dev / blog-comments

https://www.code4it.dev/
1 stars 0 forks source link

csharptips/do-not-use-nameof-for-constants #48

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

C# Tip: do NOT use nameof to give constants a value - Code4IT

In C#, nameof can be quite useful. But it has some drawbacks, if used the wrong way.

https://www.code4it.dev/csharptips/do-not-use-nameof-for-constants

pwhe23 commented 1 year ago

I kind of agree with you but use this as my preferred approach:

const string User_Table = "User_Table";

You get the power of a constant but the value won't change if someone renames it.

bellons91 commented 1 year ago

I'm totally fine with it - the const name can be in whatever format. But its value should not depend on how we named it.