Hey there, I'm Rowan. I'm currently studying Software Engineering at UTM, and I'm also an IT Entrepreneur. This is my programming blog - you'll find loads of C# stuff in here, as well as MySQL and C tutorials with source. Comments are most welcome.
I too, am a bug within Māyā.
My Other Blog(s) and Site(s)
Friend sites and blogs
My Recent Posts
My C-Sharp Ideas
Friday, July 22, 2005
Yet another cool and useful feature
The Params keyword
The params keyword could be one of the coolest features of C-Sharp, if you haven't heard of it yet. Simply put, it allows you to enter multiple parameters of a same type. An alternative to this could be the use of an array - i.e. create a method that accepts an array of a certain kind of objects, but that's really troublesome. Here, check the code out - it's pretty simple and straightforward:
What really interests us is the AddAll method. Let's have a closer look:
There's nothing particular in that method, apart from the "params" keyword used in the parameters. It's pretty strightforward. The use of the params in the parameters allows users to pass multiple values (in this case, multiple int's) of the same type - they all get kicked into an array of that object type (in this example, an array of int, which I named "numbers"). Using this function gets really easy now. All you have to do is to call the AddAll method with as much number of integer parameters as you want! Et voilà! Rien de plus façile! I called the AddAll method, and passed in a few numbers - and called the ToString() method.
Now, think of your own ways to make a good use of the params keyword ;)