Getting Property Name from an Object?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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??
 
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.
 
hi
System.Reflection and PropertyInfo Class is the way
Take a look at it in the MSDN
regards

Ansil
Dimensions
(e-mail address removed)
 
Back
Top