Thursday, June 27, 2013

What is difference between First and FirstOrDefault in LINQ?

Last week I were presenting LINQ to group of almost 100 audience. While writing query a question raised that what is difference between First and FirstOrDefault . At that time I was not very sure about answer so I asked audience to help me. One from audience answered this question. So credit of this blog to him. For benefit of all I am documenting answer below,

Let us focus on answer of this question. I am sure that you may have come across following query in LINQ.

In below query we are fetching First record on given condition.

Inline image 1

Read more: debug mode……
QR: Inline image 2