Type.Properties Property
Microsoft.DotNet.ApiReview
Gets all the public properties of the current Type.
Note: This property is an alias for
GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)
.
Syntax
public PropertyInfo[] Properties { get; }
Property Value
Type | Description |
---|---|
PropertyInfo[] | An array of PropertyInfo objects representing all the public properties of the current Type. Returns an empty array if the type has no public properties. |
Remarks
This property returns an array of PropertyInfo
objects that represent the public properties of the type. This includes instance properties and static properties. If you need to retrieve properties with different binding flags (e.g., private, inherited), use the GetProperties(BindingFlags)
method.
Examples
Retrieving Public Properties of a Type
The following example demonstrates how to retrieve and display the names of all public properties of a given type.
using System;
using System.Reflection;
public class Example
{
public static void Main(string[] args)
{
Type myType = typeof(string); // Or any other type
PropertyInfo[] properties = myType.Properties;
if (properties.Length > 0)
{
Console.WriteLine($"Public properties of {myType.Name}:");
foreach (PropertyInfo prop in properties)
{
Console.WriteLine($"- {prop.Name}");
}
}
else
{
Console.WriteLine($"The type {myType.Name} has no public properties.");
}
}
}
Requirements
Interface | Version |
---|---|
mscorlib.dll , System.dll |
.NET Framework 2.0, .NET Framework 1.1, .NET Framework 1.0 |