2

i am working with LINQ there i use First and FirstOrDefault both return the same result what is the difference

Rizwan Ali Sabir
  • 468
  • 1
  • 7
  • 18
  • have a look at to [this example](http://stackoverflow.com/documentation/c%23/68/linq-queries/329/first-firstordefault-last-lastordefault-single-and-singleordefault#t=201609220738336033875) – Adil Mammadov Sep 22 '16 at 07:38

2 Answers2

4

First and Last throw an exception if no result was found. FirstOrDefault and LastOrDefault return the result variable type's default value in that case.

Patrick
  • 668
  • 4
  • 11
0

FirstOrDefault and LastOrDefault would not throw an exception if there are no search item in sequence, they will return null.

Dmitriy Kovalenko
  • 3,437
  • 3
  • 19
  • 39