MethodBase.IsPublic Property

Gets a value that indicates whether this is a public method.

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

public bool IsPublic { get; }

Property Value

Type: System.Boolean
true if this method is public; otherwise, false.

The following example uses the IsPublic property to display a message that indicates whether the specified method is public.

using System;
using System.Reflection;
using System.Collections.Generic;

class Example
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
      BindingFlags instanceAll = BindingFlags.Public | BindingFlags.NonPublic
         | BindingFlags.Instance;

      Type t = typeof(Example);
      List<MethodBase> ctorsAndMethods = 
          new List<MethodBase>(t.GetMethods(instanceAll));

      foreach( ConstructorInfo c in t.GetConstructors(instanceAll) )

      outputBlock.Text += "Public?      Method or Constructor Description\n";

      foreach(MethodBase m in ctorsAndMethods)
         outputBlock.Text += String.Format(" {0,-6}      {1}\n",
            m.IsPublic, m.ToString());

   // Example constructors.
   private Example() {}

   protected Example(int input) {}

   public Example(string name) {}

/* This example produces the following output:

Public?    Method or Constructor Description
 True      System.String ToString()
 True      Boolean Equals(System.Object)
 True      Int32 GetHashCode()
 True      System.Type GetType()
 False     Void Finalize()
 False     System.Object MemberwiseClone()
 False     Void .ctor()
 False     Void .ctor(Int32)
 True      Void .ctor(System.String)


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