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 ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.