In C #: Why is there no β€œItem” in System.Data.DataRow?

I am rewriting / converting VB code:

Dim dt As New System.Data.DataTable() Dim dr As System.Data.DataRow = dt.NewRow() Dim item = dr.Item("myItem") 

FROM#:

 System.Data.DataTable dt = new System.Data.DataTable(); System.Data.DataRow dr = dt.NewRow(); var item = dr.Item["myItem"]; 

I can’t get it to work under C #, the problems I have is the third line var item = dr.Item["myItem"]; :

System.Data.DataRow' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'System.Data.DataRow' could be found (are you missing a using directive or an assembly reference?)

I referenced System.Data Version 4 in both projects. What am I missing here? Note: ItemArray exists in both ...

+9
source share
3 answers

Try it like this:

 var item = dr["myItem"]; 

In C #, you can directly access the indexer property. And the DataRow.Item property is defined as an indexer.

+21
source share

Actually in C # there is no Item property. In VB, access to the DataRow cell is defined as follows:

 Default Public Property Item ( column As DataColumn ) As Object 

Thus, there is the literal property "Item". However, in C # it is defined like this:

 public object this[ DataColumn column ] { get; set; } 

So this is the default property of the class / object. This way you access it using the name of the object.

+1
source share

Does anyone know a VBNET to C # converter that converts millions of parasites in my vb net project into square brackets?

0
source share

All Articles