61.7k views
0 votes
To get values of the columns of the i-th row in a DataTable object named datatable, what of the follwings is correct?

[A] DataColumn array = datatable.Rows[i].ItemArray;
[B] String[]array = datatable.Rows[i].ItemArray;
[C] Object[]array = datatable.Rows[i].ItemArray;
[D] DataRow array = datatable.Rows[i].ItemArray;

1 Answer

6 votes

Final answer:

The correct way to access the values of the i-th row's columns in a DataTable object named datatable is through the ItemArray property, with the correct answer being [C] Object[] array = datatable.Rows[i].ItemArray.

Step-by-step explanation:

The correct way to get values of the columns of the i-th row in a DataTable object named datatable is by using the ItemArray property of a DataRow. The ItemArray property returns an array of objects, so the correct answer to the question is:

[C] Object[]array = datatable.Rows[i].ItemArray;

The 'ItemArray' property gives you the values of each column in the row as an array. Since a DataColumn can contain any type of data, the array is of type Object[]. You can then access individual values by indexing into the array.

User DobromirM
by
7.8k points