Windows Dev Center

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);

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2015 Microsoft