Is there a way to add optional parameters to C# 3.0 like there will be in C# 4.0? I gotta have this feature, I just can’t wait!
Edit:
If you know a work-around/hack to accomplish this, post it also. Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use an anonymous type and reflection as a workaround to named parameters:
So now I can call Foo like this:
… and it will write my message.
Basically I’m extracting all the properties from the anonymous type that was passed, and converting them into a dictionary of string and object (the name of the property and its value).