guxiyou
asked on
Can I add an object directly to a Data Row?
Ok, this is probably an easy question, but here goes. When you add to the DataRowCollection of a DataTable, it says that there are two overloads:
1) DataRowCollection.Add(para ms object [] values)
2) DataRowCollection.Add(Data Row row)
So my question is this, if I've declared the DataTable to be a table consisting of a single row, say "ID", then can I add the single value as just DataRowCollection.Add(valu e), assuming that value is of type object? Since value is of type object, not of type object [], is this still correct (standard)? I have written a program that demonstrates that this works, but I need to know whether this is standard. So, I'll award points to the first person to explain how this behavior is/is not standard (this would include references to the standard or other credible sources).
Thanks!
1) DataRowCollection.Add(para
2) DataRowCollection.Add(Data
So my question is this, if I've declared the DataTable to be a table consisting of a single row, say "ID", then can I add the single value as just DataRowCollection.Add(valu
Thanks!
> but I need to know whether this is standard.
it is standard when you hit upon a method that has its signature like the one above. You can also use that signature for your own methods.
I'm personally not a fan of using param arrays, I think it is better to use a List of some sort, and "standard" is a bit in the eye of the beholder, but the language allows it and it certainly appears in a lot of places in the dotnet libraries.
it is standard when you hit upon a method that has its signature like the one above. You can also use that signature for your own methods.
I'm personally not a fan of using param arrays, I think it is better to use a List of some sort, and "standard" is a bit in the eye of the beholder, but the language allows it and it certainly appears in a lot of places in the dotnet libraries.
ASKER
So are you saying that it is standard because the signature is "params object [] values"? As opposed to say "object [] values"?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, that was exactly what I needed!
Note the not-so-subtle differences:
- Situation without "params". Now, as a caller, you have to define an array of type object[] and pass that on. The method will then get that array by reference.
- Situation with "params". Now, as a caller, you have to put every element of the array hard coded comma separated in the calling of the method (like you did).
> Thanks, that was exactly what I needed!
ah, great! I wasn't finished yet, as you can see ;) But thanks for the points!
ah, great! I wasn't finished yet, as you can see ;) But thanks for the points!
yes, it is a param array, meaning you can use as many objects as you want, one or more.