Type.IsPublic Property
Gets a value indicating whether the top-level Type is declared public.
[Visual Basic] Public ReadOnly Property IsPublic As Boolean [C#] public bool IsPublic {get;} [C++] public: __property bool get_IsPublic(); [JScript] public function get IsPublic() : Boolean;
Property Value
true if the top-level Type is declared public; otherwise, false.
Remarks
IsPublic and IsNotPublic get the visibility of the top-level type only.
VisibilityMask selects the visibility attributes.
Example
[Visual Basic, C#, C++] The following example creates an instance of MyTestClass, checks for the IsPublic property, and displays the result.
[Visual Basic] Imports System Imports Microsoft.VisualBasic Namespace SystemType ' Declare MyTestClass as public. Public Class MyTestClass End Class 'MyTestClass Public Class [MyClass] Public Shared Sub Main() 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 Console.WriteLine(ControlChars.Cr + "Is {0 public? {1}.", myType.FullName, myBool.ToString()) Catch e As Exception Console.WriteLine(ControlChars.Cr + "An exception occurred: {0}", e.Message.ToString()) End Try End Sub 'Main End Class '[MyClass] End Namespace 'SystemType [C#] using System; namespace SystemType { // Declare MyTestClass as public. public class MyTestClass { } public class MyClass { public static void Main(string []args) { 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; Console.WriteLine("\nIs {0} public? {1}.", myType.FullName, myBool.ToString ()); } catch (Exception e) { Console.WriteLine("\nAn exception occurred: {0}", e.Message); } } } } [C++] #using <mscorlib.dll> using namespace System; namespace SystemType { // Declare MyTestClass as public. public __gc class MyTestClass { }; public __gc class MyClass { }; } int main() { try { bool myBool = false; SystemType::MyTestClass* myTestClassInstance = new SystemType::MyTestClass(); // Get the type of myTestClassInstance. Type* myType = myTestClassInstance->GetType(); // Get the IsPublic property of the myTestClassInstance. myBool = myType->IsPublic; Console::WriteLine(S"\nIs {0} public? {1}.", myType->FullName, myBool.ToString()); } catch (Exception* e) { Console::WriteLine(S"\nAn exception occurred: {0}", e->Message); } }
[Visual Basic, C#, C++] For nested classes, ignore the results of IsPublic and IsNotPublic and pay attention only to the results of IsNestedPublic and IsNestedPrivate.
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
See Also
Type Class | Type Members | System Namespace | TypeAttributes