Hacker News new | ask | show | jobs
by Townley 476 days ago
In C# you can do

string foo = "bar";

string nameOfFoo = nameof(foo); // “foo”

Kinda nice for iterating through lists of variables and saving them to a key/value map

3 comments

nameof() is a compile time method, not a runtime method like most dynamic language equivalents.
Interesting, but it isn't causing the value (here, the "bar" string object) to know about that name.
Name of! Never knew this existed. I think it would make writing some debug statements easier and immune to renames.