Field Extension Method Point

What is the meaning of the Field extension method in a DataRow (for untyped data)?

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

with Field :

myRow.Field<Guid>("myColName") 

Without Field :

 (Guid)myRow["myColName"] 

I do not see any convincing improvements.

+4
source share
2 answers

Extension methods abstract the concept of DBNull in both directions - Field and SetField for reference types and value types with zero value. For types with null values, they are equivalent.

+2
source

The extension method supports nullable types. For instance:

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

+1
source

Source: https://habr.com/ru/post/1286697/


All Articles