Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
System Namespace
Type Class
Type Properties
 IsNested Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
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)
Visual Basic (Declaration)
Public ReadOnly Property IsNested As Boolean
Visual Basic (Usage)
Dim instance As Type
Dim value As Boolean

value = instance.IsNested
C#
public bool IsNested { get; }
Visual C++
public:
property bool IsNested {
    bool get ();
}
JScript
public function get IsNested () : boolean

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.

Visual Basic
Imports System

Public Class Example
    Protected Class NestedProtected
    End Class

    Public Class NestedPublic
    End Class

    Public Shared Sub Main()
        With GetType(NestedProtected)
            Console.WriteLine("Is " & .FullName & " nested? " & .IsNested)
        End With
        With GetType(NestedPublic)
            Console.WriteLine("Is " & .FullName & " nested? " & .IsNested)
        End With
    End Sub
End Class

' This example produces the following output:
'
'Is Example+NestedProtected nested? True
'Is Example+NestedPublic nested? True 

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

Visual C++
using namespace System;

public ref class Example
{
protected:
   ref class NestedProtected{};

public:
   ref class NestedPublic{};

   static void Main()
   {
      Type^ t = NestedProtected::typeid;
      Console::WriteLine( L"Is {0} nested? {1}",
         t->FullName, t->IsNested );
      t = NestedPublic::typeid;
      Console::WriteLine( L"Is {0} nested? {1}",
         t->FullName, t->IsNested );
   }

};

int main()
{
   Example::Main();
}

/* This example produces the following output:

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker