Type.IsPublic Property

Gets a value indicating whether the Type is declared public.

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

public bool IsPublic { get; }

Property Value

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

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.

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.

using System;

// Declare MyTestClass as public.
public class MyTestClass
public class Example
    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
            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);


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

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

Community Additions