New Improvement Of LINQ In .NET 6

We know LINQ (Language Integrated Query) is a useful feature of C# to retrieve data from different sources like SQL, Datasets, XML, EF, etc. and we all use it on daily basis in the programming world.

I want to discuss about one important improvement coming in .Net 6 is support for custom default return values for FirstOrDeafult(), LastOrDefault() and SingleOrDefault().

Usually when we use these methods the built-in default value for a type will be returned if the collection has no items. For e.g. this would be null for reference types and 0 for int types.

In .Net 6 we will be able to choose which default value should return when the collection is empty.

New Improvement Of LINQ In .NET 6