O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.8. Passing variable numbers of parameters into C# methods

This is a useful feature in C# which is not found in Java. Using the C# params keyword, a method can take in a variable number of parameters (which may not be known until runtime).

The params keyword will be useful for writing methods in shared codes, in which the programmer wants to provide maximum convenience and flexibility for users. The parameters are taken in as an array (you can take in an array of object types [9] – which means it can accept anything since every C# object is a subclass of object).

[9] object is an alias for the System.Object class, which is the ultimate superclass for all classes in C#.

This is how you declare a method called Test1 which takes in an arbritrary ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required