Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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



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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: