Possible Duplicate:
How do I get the name of a property from a property in C# (2.0)
I need some method that is going to get the property’s string name, I don’t know if this is possible in C#, is it ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using expression trees in C# 3 and .NET 3.5 you can do something close:
or you can use anonymous types and reflection:
but both are kinda hacky. (I have a blog post with an example of the latter, admittedly for a slightly different purpose, but it demonstrates the general idea.) If you could tell us more about why you need to know this, we may be able to advise you better.