C#’s params keyword makes variable parameter functions easy

I don’t know why I didn’t know this earlier, but C# has a nifty language element called params that lets you do multi parameter functions nice and easy. Instead of assigning an array as a parameter, which means explicitly creating and populating an array in your calling code, you can use do void foo(params int[] myparams) and call it with foo(1, 2, 3, 4) etc. This is much nicer for the caller, and judging from my preliminary tests, it looks like it’s backward compatible with older method calls, so you can add the params keyword to an existing function that takes an array without having to change all the old references.

Technorati Tags: