Type.IsPublic Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets a value indicating whether the Type is declared public.

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

Syntax

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

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

See Also

Reference

Type Class

System Namespace

TypeAttributes