0

I've ended up with two procedures, with very similar arguments and identical functionality, whose arguments are as follows:

   private string BuildResponse(string value1, string value2, params string[] parameters)
   private string BuildResponse(MyObject values, params string[] parameters)

In this case, MyObject has two properties; value1 and value2. I was initially trying to implement the second as follows:

   private string BuildResponse(MyObject values, params string[] parameters) {
       return BuildResponse (values.value1, values.value2, parameters);
   }

Unfortunately, the compiler threw a warning relating to the best overloaded method match for ... - i.e. I couldn't simply pass parameters (which is a string[]) through like this.

So - how can I pass a string[] into a method whose signature ends with a params variable?

(I'm now replacing the params string[] with another collection type instead hence the past tense, but it would be interesting to know whether what I was trying to do was even possible. If it isn't, feel free to state "no" and provide references)

1 Answer 1

2

This should have worked. The problem most likely was that value1 or value2 wasn't of type string. The params array was not the problem.

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

1 Comment

You're close, I was being a bit daft - when I created my simplified version I managed to accidentally not make a mistake that was in the live code.

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.