IsNested Property

Type.IsNested Property

Note: This property is new in the .NET Framework version 2.0.

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 */
public boolean get_IsNested ()

public function get IsNested () : boolean

Property Value

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 
 */

import System.*;

public class Example
{
    protected class NestedProtected
    {
    } //NestedProtected

    public class NestedPublic
    {
    } //NestedPublic

    public static void main(String[] args)
    {
        Type t = NestedProtected.class.ToType();
        Console.WriteLine("Is {0} nested? {1}", t.get_FullName(), 
            (System.Boolean)t.get_IsNested());
        t = NestedPublic.class.ToType();
        Console.WriteLine("Is {0} nested? {1}", t.get_FullName(),
            (System.Boolean)t.get_IsNested());
    } //main
} //Example

/* This example produces the following output:

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2016 Microsoft