0

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
}

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

Note that the values of a default ValueType created this way has each field initialized to their default values. msdn.microsoft.com/en-us/library/aa664475(v=vs.71).aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.