Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting Property Name from an Object?

0 views
Skip to first unread message

Alan No Spam

unread,
Nov 19, 2004, 3:53:31 PM11/19/04
to
Is it possible to get property name from an Object? For example I have this
class:

public class Person {
public string Address {get; set; }
}


Is there a way to get the property name "Address"?

Person p = new Person();
p.Address = "test"; // normally, we would know the name

p.PropertyName[0]; // This would return the name "Address", Does C# got
something like this??


Peter Rilling

unread,
Nov 19, 2004, 4:01:05 PM11/19/04
to
Sort of, but you will have to adapter the API to suite your needs. Take a
look at Reflection. This allows you to get class information at runtime,
including the list of properties available.

"Alan No Spam" <alan....@xxxxxxxx324354.com> wrote in message
news:ku6dnUtZ9tH...@rogers.com...

Ansil MCAD

unread,
Nov 19, 2004, 10:49:07 PM11/19/04
to
hi
System.Reflection and PropertyInfo Class is the way
Take a look at it in the MSDN
regards

Ansil
Dimensions
anz...@gmail.com

0 new messages