Difference between getting cell value using row.Field <T> (col) and based on row / column index

I'm new to C #, I had this script that worked great

foreach(DataColumn col in dataTab.Columns){
 foreach(DataRow row in dataTab.Rows){
  row.Field<decimal>(col).ToString(CultureInfo.InvariantCulture); }}

I had to use ToString(CultureInfo.InvariantCulture)to read the decimal separator. anyway, when I changed this code, looping over the row / column indices and putting dataTab[rowIndx][colIndx].ToString(CultureInfo.InvariantCulture), I get an error in the ToString method saying:

no overload for method tostring takes 1 argument

1. How can I fix this error?

  1. Why did he work the first time and not the second, what is the difference between the two methods?
+4
source share
3 answers

row.Field<T> - , - (decimal ), ToString(), , CultureInfo .

, , object. , object.ToString() , 1 .

+2
row.Field<decimal>(col).ToString(CultureInfo.InvariantCulture);

. Decimaltype ToString-overload, Cultureinfo.

dataTab[rowIndx][colIndx]

. ToString-overload, Cultureinfo.

+2

№ 2

, , ?

№ 1

?

Convert.ToString Method (Object, IFormatProvider):

Convert.ToString(dataTab[rowIndx][colIndx], CultureInfo.InvariantCulture)
+1

All Articles