PropertyInfo.PropertyType Property

July 28, 2014

Gets the type of this property.

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

public abstract Type PropertyType { get; }

Property Value

Type: System.Type
The type of this property.

The Type is String, Boolean, Int32, and so on.

To get the PropertyType property, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, get the PropertyType value.

The following example displays the type of a property.


using System;
using System.Reflection;

public class Example
{
    public int Answer
    {
        get
        {
            return 42;
        }
    }

    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
    {
        // Get a Type object for the Example type.
        Type t = typeof(Example);

        // Get a PropertyInfo object for the Answer property.
        PropertyInfo pi = t.GetProperty("Answer");

        // Display the type returned by the Answer property.
        outputBlock.Text += String.Format("The return type of the {0}.{1} property is {2}.",
             t.Name, pi.Name, pi.PropertyType) + "\n";
    }
}

/* This example produces the following output:

The return type of the Example.Answer property is System.Int32.
 */


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft