DefaultParameterValueAttribute Class

Note: This class is new in the .NET Framework version 2.0.

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)

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

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);


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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0