Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DefaultParameterValueAttribute Class

Sets the default value of a parameter when called from a language that supports default parameters. This class cannot be inherited.

Namespace: System.Runtime.InteropServices
Assembly: System (in system.dll)

[AttributeUsageAttribute(AttributeTargets.Parameter)] 
public sealed class DefaultParameterValueAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Parameter) */ 
public final class DefaultParameterValueAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Parameter) 
public final class DefaultParameterValueAttribute extends Attribute
Not applicable.

The DefaultParameterValueAttribute attribute allows you to specify a default parameter value in a language that does not otherwise support default parameters. After you apply this attribute to your code, languages that support default parameters can use the specified value as a default parameter.

Note that the DefaultParameterValueAttribute does not add support for default parameters to languages that do not support this feature. For example, if you use the DefaultParameterValueAttribute with a method written in C#, which does not support default parameters, you cannot use the default parameter when calling the method from C#. You can use the default parameter only when calling the method in a language such as C++ that does support the feature.

The DefaultParameterValueAttribute is particularly useful to specify default parameters for methods of a COM interop interface.

The following code example demonstrates how to apply the DefaultParameterValueAttribute attribute to a parameter of a method written in C#.

static public void MethodWithDefaultParam([System.Runtime.InteropServices.DefaultParameterValue("DEFAULT_PARAM_VALUE")] string var)
{
    Console.WriteLine("The passed value is: " + var);
}

System.Object
   System.Attribute
    System.Runtime.InteropServices.DefaultParameterValueAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft