how can i get the variable name in C#.Net?
Like
string name = "myname";
So my out put is should com "name".
not "myname"
i found in java it can do getFieldName() method. like wise what is the method in C#.Net? can u post the full example codes?
C# method
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Sachin Gaur12 reputationPosted Dec 11, 2007, 6:40 PM EST
FieldInfo[] myFieldInfo;
Type myType = this.GetType();
myFieldInfo = myType.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
for (int i = 0; i < myFieldInfo.Length; i++)
{
MessageBox.Show(myFieldInfo[i].Name);
}
Jan MontanoRank #1,295 · 1.3K reputationPosted Dec 11, 2007, 8:36 PM EST
programmer. The CLR doesn't need these names, so they are eliminated in
the compilation process."
source : Getting class instance names via reflection
Mohamed Ihjas14 reputationPosted Dec 12, 2007, 7:49 PM EST