Difference Between First() And FirstOrDefault()?
Difference Between First() And FirstOrDefault()? can anyone explain me with the help of an example?
Add comment
Answers (1)
Add AnswerThe difference between First and FirstOrDefault is that First() will throw an exception if there is no result data for the supplied criteria whereas FirstOrDefault() will return the default value (null) if there is no result data.
- First() will throw an exception if there is result data is null, as you can see below.
- FirstOrDefault() return null (default value). If, There is result data is null. As you can see below.
I hope this will help you to understand the difference between First() and FirstOrDefault().
Thank you.