Check if current Type represents a type whose definition is nested inside the definition of another type in CSharp

Description

The following code shows how to check if current Type represents a type whose definition is nested inside the definition of another type.

Example


using System;/*from   www  . j  av  a2 s.  c om*/

public class Example
{
    protected class NestedProtected
    {
    }

    public class NestedPublic
    {
    }

    public static void Main()
    {
        Type t = typeof(NestedProtected);
        Console.WriteLine("Is {0} nested? {1}", t.FullName, t.IsNested);
        t = typeof(NestedPublic);
        Console.WriteLine("Is {0} nested? {1}", t.FullName, t.IsNested);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type