Export (0) Print
Expand All

PropertyInfo.GetValue Method (Object, Object[])

.NET Framework 1.1

Returns the value of the property with optional index values for indexed properties.

[Visual Basic]
Overloads Public Overridable Function GetValue( _
   ByVal obj As Object, _
   ByVal index() As Object _
) As Object
public virtual object GetValue(
 object obj,
 object[] index
public: virtual Object* GetValue(
 Object* obj,
 Object* index __gc[]
public function GetValue(
   obj : Object,
 index : Object[]
) : Object;


The object whose property value will be returned.
Optional index values for indexed properties. This value should be a null reference (Nothing in Visual Basic) for non-indexed properties.

Return Value

The property value for the obj parameter.


Exception Type Condition
ArgumentException The index array does not contain the type of arguments needed.


The property's Get method is not found.

TargetException The object does not match the target type, or a property is an instance property but obj is a null reference (Nothing in Visual Basic).
TargetParameterCountException The number of parameters in index does not match the number of parameters the indexed property takes.
MethodAccessException There was an illegal attempt to access a private or protected method inside a class.


This is a convenience method that provides an implementation for the abstract GetValue method with a BindingFlags parameter of DefaultChangeType, the Binder set to a null reference (Nothing in Visual Basic), and the CultureInfo set to a null reference (Nothing).

Because static properties belong to the type, not individual objects, get static properties by passing a null reference (Nothing) as the object argument. For example, use the following code to get the static CurrentCulture property of CultureInfo:

PropertyInfo CurCultProp = (typeof(CultureInfo)).GetProperty("CurrentCulture");

Console.WriteLine("CurrCult: " + CurCultProp.GetValue(null,null));

To use the GetValue method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the GetValue method.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

.NET Framework Security: 

See Also

PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace | PropertyInfo.GetValue Overload List

© 2014 Microsoft