C# ParameterInfo DefaultValue

Description

ParameterInfo DefaultValue Gets a value indicating the default value if the parameter has a default value.

Syntax

ParameterInfo.DefaultValue has the following syntax.


public virtual Object DefaultValue { get; }

Example


using System;//www .  j a  v  a2  s .  c  om
using System.Reflection;
using System.Threading;
using System.Reflection.Emit;

public class ParameterInfo_IsIn_IsOut_IsOptional
{
   public static void Main()
   {
      Assembly[] myAssemblies = Thread.GetDomain().GetAssemblies();
      Assembly myAssembly = null;
      Type myType = myAssembly.GetType("MyType");
      MethodBase myMethodBase = myType.GetMethod("MyMethod");
      ParameterInfo[] myParameters = myMethodBase.GetParameters();
      for(int i = 0; i < myParameters.Length; i++)
      {
         Console.WriteLine(myParameters[i].DefaultValue);
      }
   }
}




















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo