C# ParameterInfo HasDefaultValue
Description
ParameterInfo HasDefaultValue
Gets a value that indicates
whether this parameter has a default value.
Syntax
ParameterInfo.HasDefaultValue
has the following syntax.
public virtual bool HasDefaultValue { get; }
Example
using System;//from ww w. j av a 2 s. c o m
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].HasDefaultValue);
}
}
}