I have an optional parameter of type IEnumerable<int> in my C# method. Can I initialize it with anything but null, e.g. a fixed list of values?
I have an optional parameter of type IEnumerable<int> in my C# method. Can I
Share
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.
No. You can only have compile time constants. You can assign in to null and then
Next code snippet is take from well-known
C# in Depthbook byJon Skeet. Page 371. He suggest to use null as kind ofnot setindicator for parameters, that may have meaningful default values.Usage