Get property using the specified binding constraints in CSharp

Description

The following code shows how to get property using the specified binding constraints.

Example


using System;//from ww w. j a  va 2 s .c  o  m
using System.Reflection;
class MyClass
{
    private int myProperty;
    public int MyProperty
    {
        get
        {
            return myProperty;
        }
        set
        {
            myProperty=value;
        }
    }
}
public class MyTypeClass
{
    public static void Main(string[] args)
    {
        Type myType=typeof(MyClass);       
        PropertyInfo myPropInfo = myType.GetProperty("MyProperty", BindingFlags.Public | BindingFlags.Instance);
        Console.WriteLine("{0} is a property of MyClass.", myPropInfo.Name);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type