I have an C# API that can take 0/1/Many paramters of same type. What should be better way to have a API defined = params versus IEnumerable<T>?
I have an C# API that can take 0/1/Many paramters of same type. What
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.
I would almost always use
paramsfor APIs like that, since it allows the caller to pass the arguments without having to manually construct a container for them.This:
is just cleaner than requiring this:
However, if you are specifically operating on a single sequence of items, then
IEnumerable<T>is more sensible. As well, if you expect > 5 or so parameters, then an enumerable makes more sense, since at that point the calling method starts to look pretty bad.It really comes down to the logical operation of the API, along with the number of parameters you are actually expecting.