Hi,
I am wondering if there is a way in C# to get the name of a variable. Let's
say:
int MyName=3;
How can I get a string with the Value "MyName"? Any ideas on that?
Thanks
Azat 8 1138
Hi,
This should only work with the variable is a member of a type, it will not
work if the variable is declared inside a method for example.
Also this do not solve the OP's problem he want to know the name of a
particular variable, not to get a list of the fields of a type.
AFAIK, there is no way to know the name of a variable.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Lebesgue" <no****@spam.jp> wrote in message
news:OZ**************@TK2MSFTNGP15.phx.gbl... Hi, I am wondering if there is a way in C# to get the name of a variable. Let's say:
int MyName=3;
How can I get a string with the Value "MyName"? Any ideas on that?
You can get it by using reflection.
Type aType = Type.GetType("YourClassName"); FieldInfo[] fields = aType.GetFields();
FieldInfo has property Name.
http://msdn.microsoft.com/library/de...ieldstopic.asp
http://msdn.microsoft.com/library/de...classtopic.asp
Hi,
This should only work with the variable is a member of a type, it will not
work if the variable is declared inside a method for example.
Also this do not solve the OP's problem he want to know the name of a
particular variable, not to get a list of the fields of a type.
AFAIK, there is no way to know the name of a variable.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Lebesgue" <no****@spam.jp> wrote in message
news:OZ**************@TK2MSFTNGP15.phx.gbl... Hi, I am wondering if there is a way in C# to get the name of a variable. Let's say:
int MyName=3;
How can I get a string with the Value "MyName"? Any ideas on that?
You can get it by using reflection.
Type aType = Type.GetType("YourClassName"); FieldInfo[] fields = aType.GetFields();
FieldInfo has property Name.
http://msdn.microsoft.com/library/de...ieldstopic.asp
http://msdn.microsoft.com/library/de...classtopic.asp
Ignacio Machin ( .NET/ C# MVP ) wrote: Hi,
This should only work with the variable is a member of a type, it will not work if the variable is declared inside a method for example.
Also this do not solve the OP's problem he want to know the name of a particular variable, not to get a list of the fields of a type.
AFAIK, there is no way to know the name of a variable.
This would make sense; after all the semantics at runtime shouldn't
depend on irrelevant details of the source, right? I mean, presumably
if you take a program and just change all the (private) variable names,
you will compile to identical IL...
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation "Lebesgue" <no****@spam.jp> wrote in message news:OZ**************@TK2MSFTNGP15.phx.gbl... Hi, I am wondering if there is a way in C# to get the name of a variable. Let's say:
int MyName=3;
How can I get a string with the Value "MyName"? Any ideas on that?
You can get it by using reflection.
Type aType = Type.GetType("YourClassName"); FieldInfo[] fields = aType.GetFields();
FieldInfo has property Name.
http://msdn.microsoft.com/library/de...ieldstopic.asp
http://msdn.microsoft.com/library/de...classtopic.asp
Ignacio Machin ( .NET/ C# MVP ) wrote: Hi,
This should only work with the variable is a member of a type, it will not work if the variable is declared inside a method for example.
Also this do not solve the OP's problem he want to know the name of a particular variable, not to get a list of the fields of a type.
AFAIK, there is no way to know the name of a variable.
This would make sense; after all the semantics at runtime shouldn't
depend on irrelevant details of the source, right? I mean, presumably
if you take a program and just change all the (private) variable names,
you will compile to identical IL...
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation "Lebesgue" <no****@spam.jp> wrote in message news:OZ**************@TK2MSFTNGP15.phx.gbl... Hi, I am wondering if there is a way in C# to get the name of a variable. Let's say:
int MyName=3;
How can I get a string with the Value "MyName"? Any ideas on that?
You can get it by using reflection.
Type aType = Type.GetType("YourClassName"); FieldInfo[] fields = aType.GetFields();
FieldInfo has property Name.
http://msdn.microsoft.com/library/de...ieldstopic.asp
http://msdn.microsoft.com/library/de...classtopic.asp
Larry Lard <la*******@hotmail.com> wrote: AFAIK, there is no way to know the name of a variable.
This would make sense; after all the semantics at runtime shouldn't depend on irrelevant details of the source, right? I mean, presumably if you take a program and just change all the (private) variable names, you will compile to identical IL...
No - the private type/member variable names are still present in the
IL, but not *local* variable names.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Larry Lard <la*******@hotmail.com> wrote: AFAIK, there is no way to know the name of a variable.
This would make sense; after all the semantics at runtime shouldn't depend on irrelevant details of the source, right? I mean, presumably if you take a program and just change all the (private) variable names, you will compile to identical IL...
No - the private type/member variable names are still present in the
IL, but not *local* variable names.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dennis Westermann |
last post by:
I have the following problem
XML-File:
<SEARCH>
<TAG>'x' or 'y'</TAG>
</SEARCH>
<CHARLIST>
<CHAR>a</CHAR>
<CHAR>x</CHAR>
|
by: Randell D. |
last post by:
HELP!
I am determined to stick with this... I'm getting there... for those who
haven't read my earlier posts, I'm createing what should be a simple
function that I can call to check that...
|
by: SB |
last post by:
Hello. I have an input file which is laid out in the following manner...
Name
Day 1
am time 1
am time 2
appointment
pm time 1
pm time 2
appointment
Day 2
|
by: Shane |
last post by:
Hi,
Thanks in advance for the help. I have been to many websites and tried
several solutions to my problem, but have fixed part of it. It's time to
come humbly to the newsgroups for help :-)
...
|
by: Eric Lilja |
last post by:
Hello, I have a text file that contains a number of entries describing a
recipe. Each entry consists of a number of strings. Here's an example file
with only one entry (recipe):
Name=Maple Quill...
|
by: Bo Yang |
last post by:
Hi,
I am now reading the C++ standard, and have some troubles.
What is unqualified name and what is qualified name?
I found the standard is too hard for non-english programmer!
|
by: jenniamia |
last post by:
I'm new to programming, so this might be simpler than I realize but I'd appreciate a push in the right direction.
I'm using VS.NET 2005 with a database, SQL 2000. I'm writing in C# code and I'm...
|
by: arnuld |
last post by:
This is the partial-program i wrote, as usual, i ran into problems
halfway:
/* C++ Primer - 4/e
*
* Exercise 8.9
* STATEMENT:
* write a function to open a file for input and then read...
|
by: googletired |
last post by:
Hello,
I've been working on this for a days and getting frustrated. Basically i want read a master xml file that references many other xml files and use this information to output an RSS Feed.
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |