Export (0) Print
Expand All
Expand Minimize

Type.IsNested Property

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public bool IsNested { get; }

Property Value

Type: System.Boolean
true if the Type is nested inside another type; otherwise, false.

The IsNested property returns true for all nested types, regardless of visibility. To test for nesting and visibility at the same time, use the related properties IsNestedAssembly, IsNestedFamily, IsNestedFamANDAssem, IsNestedFamORAssem, IsNestedPrivate, or IsNestedPublic.

NoteNote

The VisibilityMask enumeration member selects the visibility attributes for a type.

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

using System;

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);
    }
}

/* This example produces the following output:

Is Example+NestedProtected nested? True
Is Example+NestedPublic nested? True 
 */

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft