I have recently started .NET programming, and looked at both VB.NET and C#.
In VB.NET, a strongly typed Datatable cosisted of a collection of strongly types rows. Therefore, for example, this statement would work:
lCustomerTable As CustomerDataSet.CustomerTable
lCustomerRow as CustomerDataSet.CustomerTable.CustomerRow
lCustomerTable = TableAdapter.GetData
lCustomerRow = lCustomerTable.Rows(0)
However in C#, it seems i have to explicitly cast the returned Row to a CustomerRow:
lCustomerRow = (CustomerDataSet.CustomerTable.CustomerRow)lCustomerTable.Rows[0]
Is there any reason for this? Should the dataset not create the object type definitions when creating the table adapters and SQL dataTables?
I don’t think
Rowsis actually strongly typed, even for typed datasets. The difference is that VB, by default, permits implicit downcasts. E.g. you can write:This is only disabled if you use
Option Strict– try that in VB and see if your code still compiles…In C#, the downcasts must always be explicit – it doesn’t have a “non-strict mode”.