1

Can IEnumerable be a possible alternative to params[]?

Because Ive been hearing some articles that params is not good, but I seem to doubt it because it is syntactically straightforward and is very useful.

ex.

public void testMeth(IEnumerable<object> testerEnum){
    //Code here
}
Reyn
  • 77
  • 10

1 Answers1

2

Using the params keyword importantly allows callers of your method not to wrap the arguments into a collection at all.

With:

public bool testMeth(params object[] input){
    // ... things
    return purity >= REQUIRED_PURITY; //this is how to test meth, right?
}

The caller can call

var is_good = testMeth("apples", new object(), 7);

with no need to make their own array.

moreON
  • 1,977
  • 17
  • 19