System.Reflection.Type

Documentation > .NET API Browser > System > System.Reflection > Type > GetProperties

GetProperties Method

public PropertyInfo[] GetProperties()

When overridden in a derived class, gets all public properties of the current Type.

The GetProperties method returns an array of PropertyInfo objects representing the public properties of the type. This includes properties inherited from base classes and implemented interfaces. If the type has no public properties, an empty array is returned.

Parameters

This method does not take any parameters.

Returns

An array of type PropertyInfo representing all the public properties of the current Type. Returns an empty array if there are no public properties.

Example


using System;
using System.Reflection;

public class MyClass
{
    public string MyProperty { get; set; }
    public int AnotherProperty { get; set; }
}

public class Program
{
    public static void Main(string[] args)
    {
        Type myType = typeof(MyClass);
        PropertyInfo[] properties = myType.GetProperties();

        Console.WriteLine($"Public properties of {myType.Name}:");
        foreach (PropertyInfo property in properties)
        {
            Console.WriteLine($"- {property.Name} ({property.PropertyType.Name})");
        }
    }
}
                    

See Also