let's say I have a var,
string variableName = "hello world";
How can I get the name of my variable and not it's value?
string x = variableName.name();
//x = "variableName"
let's say I have a var,
string variableName = "hello world";
How can I get the name of my variable and not it's value?
string x = variableName.name();
//x = "variableName"
You can use
var name = nameof(x);
to get "x" in a string named "name", where x is the variable you want.
However, it will only work with modern flavours of C#. For older ones, you'll have to use Expression, which is a PITA, both for performances and in terms of code complexity for a such simple need.
edit : more details here : get name of a variable or parameter