Type.IsPublic Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets a value indicating whether the Type is declared public.

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

Syntax

'Declaration
Public ReadOnly Property IsPublic As Boolean
public bool IsPublic { get; }

Property Value

Type: System.Boolean
true if the Type is declared public and is not a nested type; otherwise, false.

Remarks

Do not use with nested types; use IsNestedPublic instead.

If the current Type represents a type parameter of a generic type, this property returns true.

TypeAttributes.VisibilityMask selects the visibility attributes.

Examples

The following example creates an instance of MyTestClass, checks for the IsPublic property, and displays the result.

For nested classes, ignore the results of the IsPublic and IsNotPublic properties and use IsNestedPublic, IsNestedPrivate, IsNestedFamORAssem, and so on.

' Declare MyTestClass as public.
Public Class MyTestClass
End Class 

Public Class Example
    Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
        Try
            Dim myBool As Boolean = False
            Dim myTestClassInstance As New MyTestClass()
            ' Get the type of myTestClassInstance.
            Dim myType As Type = myTestClassInstance.GetType()
            ' Get the IsPublic property of myTestClassInstance.
            myBool = myType.IsPublic
            outputBlock.Text &= String.Format("Is {0} public? {1}." & vbLf, _
                myType.Name, myBool)
        Catch e As Exception
            outputBlock.Text &= _
                String.Format("An exception occurred: {0}" & vbLf, e.Message) 
        End Try
    End Sub 
End Class 
using System;

// Declare MyTestClass as public.
public class MyTestClass
{
}
public class Example
{
    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
    {
        try
        {
            bool myBool = false;
            MyTestClass myTestClassInstance = new MyTestClass();
            // Get the type of myTestClassInstance.
            Type myType = myTestClassInstance.GetType();
            // Get the IsPublic property of the myTestClassInstance.
            myBool = myType.IsPublic;
            outputBlock.Text += 
                String.Format("Is {0} public? {1}.\n", myType.FullName, myBool);
        }
        catch (Exception e)
        {
            outputBlock.Text += 
                String.Format("An exception occurred: {0}\n", e.Message);
        }
    }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.