PropertyInfo.GetValue Method (Object, Object[])


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

Namespace:   System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public virtual object GetValue(
	object obj,
	object[] index


Type: System.Object

The object whose property value will be returned.

Type: System.Object[]

Optional index values for indexed properties. The indexes of indexed properties are zero-based. This value should be null for non-indexed properties.

Return Value

Type: System.Object

The property value of the specified object.

Exception Condition

The index array does not contain the type of arguments needed.


The property's get accessor is not found.


The object does not match the target type, or a property is an instance property but obj is null.


The number of parameters in index does not match the number of parameters the indexed property takes.


In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, MemberAccessException, instead.

There was an illegal attempt to access a private or protected method inside a class.


An error occurred while retrieving the property value. For example, an index value specified for an indexed property is out of range. The InnerException property indicates the reason for the error.

To determine whether a property is indexed, use the GetIndexParameters method. If the resulting array has 0 (zero) elements, the property is not indexed.

This is a convenience method that provides an implementation for the abstract GetValue method with a BindingFlags parameter of Default, the Binder set to null, and the CultureInfo set to null.

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

PropertyInfo CurCultProp = 
Console.WriteLine("CurrCult: " +

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


Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public members if the caller has been granted ReflectionPermission with the ReflectionPermissionFlag.RestrictedMemberAccess flag and if the grant set of the non-public members is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

To use this functionality, your application should target the .NET Framework 3.5 or later.

The following example shows how to get the value of an indexed property. The String.Chars property is the default property (the indexer in C#) of the String class.

using System;
using System.Reflection;

class Example
    public static void Main()
        string test = "abcdefghijklmnopqrstuvwxyz";

        // Get a PropertyInfo object representing the Chars property.
        PropertyInfo pinfo = typeof(string).GetProperty("Chars");

        // Show the first, seventh, and last letters
        ShowIndividualCharacters(pinfo, test, 0, 6, test.Length - 1);

        // Show the complete string.
        Console.Write("The entire string: ");
        for (int x = 0; x < test.Length; x++)
            Console.Write(pinfo.GetValue(test, new Object[] {x}));

    static void ShowIndividualCharacters(PropertyInfo pinfo, 
                                         object value,
                                         params int[] indexes)
       foreach (var index in indexes) 
          Console.WriteLine("Character in position {0,2}: '{1}'",
                            index, pinfo.GetValue(value, new object[] { index }));
// The example displays the following output:
//    Character in position  0: 'a'
//    Character in position  6: 'g'
//    Character in position 25: 'z'
//    The entire string: abcdefghijklmnopqrstuvwxyz


for accessing non-public members when the grant set of the non-public members is restricted to the caller's grant set, or a subset thereof. Associated enumeration: ReflectionPermissionFlag.RestrictedMemberAccess


for accessing non-public members regardless of their grant set. Associated enumeration: ReflectionPermissionFlag.MemberAccess


when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top