C# Type IsNested

Description

Type IsNested gets a value indicating whether the current Type object represents a type whose definition is nested inside the definition of another type.

Syntax

Type.IsNested has the following syntax.


public bool IsNested { get; }

Example

The following code example displays the value of the IsNested property for both a protected nested class and a public nested class.


using System;/*www .  j a  v  a  2 s .co  m*/

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 »
    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