What’s the difference between FirstOrDefault() and FirstOrDefault<string>() in LINQ ?
Could somebody give me some simple explanation?
TypedDataSet ds= codeComponent.GetAllCode("test");
string status = (from s in ds.Codes
where s.Name == "hello"
select s.Remarks).FirstOrDefault();
TypedDataSet ds= codeComponent.GetAllCode("test");
string status = (from s in ds.Codes
where s.Name == "hello"
select s.Remarks).FirstOrDefault<string>();
No semantic difference; the compiler is able to infer the generic argument from the type of the collection. Just syntactic sugar that makes our lives a little bit simpler.
Note that this is not specific to LINQ; the spec defines when generic arguments may be inferred as well as when they cannot.