Get public types nested in the current Type in CSharp

Description

The following code shows how to get public types nested in the current Type.

Example


using System;//from   w  w w  . j av a2 s .c om
using System.Reflection;
public class MyClass 
{
    public class NestClass 
    {
        public static int myPublicInt=0;
    }
    public struct NestStruct
    {
        public static int myPublicInt=0;
    }
}

public class MyMainClass 
{
    public static void Main() 
    {
        Type myType=typeof(MyClass);
        Type[] nestType=myType.GetNestedTypes();
        Console.WriteLine("The number of nested types is {0}.", nestType.Length);
        foreach(Type t in nestType)
            Console.WriteLine("Nested type is {0}.", t.ToString());
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type