views:

112

answers:

2

What is the point of the Field extension method on DataRow (for untyped DataTables)?

Here is a comparison of using Field or not using it.

with Field:

myRow.Field<Guid>("myColName")

without Field:

(Guid)myRow["myColName"]

I don't see any compelling improvement.

A: 

The extension method supports nullable types. For instance:

myRow.Field<Guid?>("myColName")

Joseph Daigle
ok so what about myRow["myColName"] as Guid?
JoelFan
I suppose that does work...
Joseph Daigle
+1  A: 

The extension methods abstract away the concept of DBNull, in both directions - Field and SetField, for reference types and nullable value types. For non-nullable value types they are equivalent.

dahlbyk