Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the value of default(IEnumerable<T>)?

Tags:

c#

.net-4.0

What is the value of default(IEnumerable<T>) in .NET 4.0, C# ? (Pretty much straightforward)

like image 485
John Isaiah Carmona Avatar asked Feb 03 '12 06:02

John Isaiah Carmona


People also ask

What is IEnumerable T in C#?

IEnumerable interface is a generic interface which allows looping over generic or non-generic lists. IEnumerable interface also works with linq query expression. IEnumerable interface Returns an enumerator that iterates through the collection.

What is the default value of FirstOrDefault C#?

The default value for reference and nullable types is null . The FirstOrDefault method does not provide a way to specify a default value. If you want to specify a default value other than default(TSource) , use the DefaultIfEmpty<TSource>(IEnumerable<TSource>, TSource) method as described in the Example section.

What is IEnumerable in ASP NET MVC?

IEnumerable will execute select query on server side, load data in-memory on client side and then filter data. IEnumerable can be used for querying data from in-memory collections like List, Array etc.


2 Answers

null

default Keyword:

will be null for reference types and zero for value types.

IEnumerable is not value type, so result will be null

like image 57
archil Avatar answered Oct 19 '22 19:10

archil


It is null because it is a reference type.

like image 38
jdehaan Avatar answered Oct 19 '22 19:10

jdehaan