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)
Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Parameter)> _
Public NotInheritable Class DefaultParameterValueAttribute _
Inherits Attribute
Dim instance As DefaultParameterValueAttribute
[AttributeUsageAttribute(AttributeTargets.Parameter)]
public sealed class DefaultParameterValueAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Parameter)]
public ref class DefaultParameterValueAttribute sealed : public 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);
}
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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
Reference