Reputation: 28586
How to initialize an optional paramerer for a structure type in C# ?
Is it possible in .NET 4.5?
string Foo(string myArg, KeyValuePair<string, string> myOptionalArg = ???)
{
// todo
}
Upvotes: 0
Views: 1495
Reputation: 203847
Yes, you can initialize the optional argument to any compile time literal value that is of the appropriate type. For KeyValuePair
the only compile time literal that is of that type (at least in any version of C# that currently exists) will be default(KeyValuePair<string, string>)
.
Upvotes: 5