Tuesday, April 28, 2015

C# - using "params" in method parameter


You can define a method with "params":

void Method(string s, params object[] param)

That means, you can use this code to add parameters to the method 

Customer customer;
Method("bla", customer.CustomerID, customer.CustomerSearchName);

instead of defining this:

void MethodKacke(string s, object[] param)

Then the method parameters had to  be like this:


MethodKacke("bla", new object[] { customer.CustomerID, customer.CustomerSearchName });

So using params is the more easy way. :-)