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?
Loading
Mohamed IhjasPosted Dec 13, 2007, 12:49 AM
Jan MontanoPosted Dec 12, 2007, 1:36 AM
programmer. The CLR doesn't need these names, so they are eliminated in
the compilation process."
source : Getting class instance names via reflection
Sachin GaurPosted Dec 11, 2007, 11:40 PM
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);
}