I’m trying to do like this:
public int Insert(object o, string[] ignore = new string[] {"Id"})
but it tells me that I can’t do that ?
why is that so ?
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.
The problem is that the default arguments must be constants. Here you are dynamically allocating an array. As with declaring
constvariables, for reference types only string literals and nulls are supported.You can achieve this by using the following pattern
Now when the caller excludes the argument at the call site, the compiler will pass the value
nullwhich you can then handle as required. Note that jsut to keep it simple I have modified the value of the argument in the function, not generally considered good practice but I believe this might be alright in this scenario.