Through this blog, I would like to share how to pass an array as a parameter, while calling an ASP.NET Web API.
Thus, let's begin by creating the same. This blog is strictly to comprehend how to pass an array as parameter while calling ASP.NET Web API.
Consider that you want to perform some basic operation like Addition, Multiplication etc. by passing two or more parameters. However, the number of parameters is not specific.
- public class BasicOperationPerform : BasicOperationBase
- {
- public override double PerformOperation(string operation, double n1, double n2, params double[] nn)
- {
- double result = 0;
- if (operation == "ADD")
- {
- Addition add = new Addition();
- double totaladdition = add.GetAddition(n1, n2, nn);
- result = totaladdition;
- }
- else if (operation == "SUB")
- {
- Subtraction add = new Subtraction();
- double totalsubtraction = add.GetSubtraction(n1, n2, nn);
- result = totalsubtraction;
- }
- else if (operation == "MUL")
- {
- Multiplication add = new Multiplication();
- double totalMultiplication = add.GetMultiplication(n1, n2, nn);
- result = totalMultiplication;
- }
- else if (operation == "DIV")
- {
- Division add = new Division();
- double totaladdition = add.GetDivision(n1, n2, nn);
- result = totaladdition;
- }
- return result;
- }
Now, let us create an APIController and observe whether the implemented stuff is sufficient for the requirement or not.

Join the conversation! Your thoughts help the community grow.