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.
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System.Booleantrue 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.
Note: |
|---|
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8. |
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); } } }
Note: