The Add method accepts a params array.  If you're unfamiliar with this
concept, google it, and you'll see how it works.  Basically, a params
array accepts zero-to-many objects either one at a time, or in an
actual array.  The method itself treats it as an array, but it gives
you the flexibility of calling the method the way you're doing it.

The advantage is that you have the choice of doing it both ways - you
can put the values in one at a time, or you can already have an array
previously defined, and pass that array in.  The method doesn't know
the difference, and doesn't care.

On Apr 9, 7:04 am, Mike <[email protected]> wrote:
> Hi,
> Here is a really basic question that I am struggling with. What is the
> difference between the following lines:
>
> DataGrid.Rows.Add(new Object[] { "Theodore", "Roosevelt",
> "President" });
> and
> DataGrid.Rows.Add("Theodore", "Roosevelt", "President" );
>
> I am working with a data grid view in C# and both lines compile and
> appear to do the same thing functionally when run. I assume specifying
> new Object[]  is a type cast of some sort and not really needed in
> this case?
>
> The specific question I guess is if the program works without the new
> Object[] why would I want to put it there?
>
> Thanks in advance.
> Mike

Reply via email to