C# Type GetNestedType(String)

Description

Type GetNestedType(String) searches for the public nested type with the specified name.

Syntax

Type.GetNestedType(String) has the following syntax.


public Type GetNestedType(
  string name
)

Parameters

Type.GetNestedType(String) has the following parameters.

  • name - The string containing the name of the nested type to get.

Returns

Type.GetNestedType(String) method returns An object representing the public nested type with the specified name, if found; otherwise, null.

Example


/*  w w  w . j a v  a 2  s  .  co  m*/
using System;
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() 
    {
        try
        {
            Type myType=typeof(MyClass);

            Type nestType=myType.GetNestedType("NestClass");
            Console.WriteLine(nestType);
        }
        catch(Exception e)
        {
            Console.WriteLine("Error"+e.Message);  
        }         
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version