Reputation: 3888
I'm designing a cmdlet using plain C#. Is it possible to define a default value for a parameter?
Script cmdlet:
[Parameter] [string] $ParameterName = "defaultValue"
Which is the equivalent for C#?
[Parameter]
public string ParameterName { get; set; }
Upvotes: 8
Views: 6481
Reputation: 9506
Since C# 6.0 has been released:
[Parameter]
public string ParameterName { get; set; } = "defaultValue";
Upvotes: 10
Reputation: 18430
With auto-implemented properties, you can't. You will need to create the actual getter and setter.
Something like this:
private string _ParameterName = "defaultvalue";
[Parameter]
public string ParameterName
{
get
{
return _ParameterName ;
}
set
{
_ParameterName = value;
}
}
Upvotes: 10