Expand Minimize

Type::IsNotPublic Property

Gets a value indicating whether the Type is not declared public.

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

public:
virtual property bool IsNotPublic {
	bool get () sealed;
}

Property Value

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

Implements

_Type::IsNotPublic

Do not use this property with nested types; use the IsNestedPublic property instead.

If the current Type represents a type parameter of a generic type, this property returns false.

This example uses the IsNotPublic property to get the visibility of the type.

using namespace System;
using namespace System::IO;
using namespace System::Reflection;

int main()
{
   //Get the Type and MemberInfo.
   Type^ t = Type::GetType("System.IO.File");
   array<MemberInfo^>^ members = t->GetMembers();

   //Get and display the DeclaringType method.
   Console::WriteLine("There are {0} members in {1}.",
                      members->Length, t->FullName );
   Console::WriteLine("Is {0} non-public? {1}",
                      t->FullName, t->IsNotPublic );
}
// The example displays the following output: 
//       There are 60 members in System.IO.File. 
//       Is System.IO.File non-public? False

The following code example demonstrates why you cannot use IsPublic and IsNotPublic for nested classes.

public ref class A
{
public:
   ref class B{};


private:
   ref class C{};


};

For nested classes, ignore the results of IsPublic and IsNotPublic and pay attention only to the results of IsNestedPublic and IsNestedPrivate. The reflection output for this code fragment would be as follows:

Class

IsNotPublic

IsPublic

IsNestedPublic

IsNestedPrivate

A

FALSE

TRUE

FALSE

FALSE

B

FALSE

FALSE

TRUE

FALSE

C

FALSE

FALSE

FALSE

TRUE

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft