tags:

views:

392

answers:

3

One of the method signatures for the DataRow Add Method is:

DataRow.Add(params object[] values)

When using the above, if I am passing in some strings for example, do I have to do it like the following:

DataRow.Add(new object[]{"a","b","c"});

or can I just do it like the following:

DataRow.Add("a","b","c");

Would both ways work?

The same question applies to the a collection of DataColumns when passing adding columns to a DataTable using the AddRange method. Do I have to use DataTable.Columns.AddRange(new DataColumn[]{}) or can I just pass the columns without instantiating a new array (meaning does it do it indirectly)

+3  A: 

Yes, both ways would work. The params keyword is magic like that.

mquander
Yes this is what I was thinking.
Xaisoft
+3  A: 

Yes, the both will work fine. Though the second syntax is preferable.

Koistya Navin
+1  A: 

IMHO, both ways should work, since the signature declares the array as a 'params' argument. If the method wouldn't be able to handle it in this way, they shouldn't have declared the array argument as 'params'.

Frederik Gheysels