First - It returns first specific element from a collection of elements if one or more than one match found for that element. An exception is thrown, if no match is found for that element in the collection.
FirstOrDefault - It returns first specific element from a collection of elements if one or more than one match found for that element. A default value is returned, if no match is found for that element in the collection.
When to Use ?
1. When you always want one record no matter what the result set contains, use First or FirstOrDefault.
2. When you want a default value if the result set contains no record, use FirstOrDefault
#linq #code #linqinterviewquestion #sql #sqlserver #sqlservertutorial #programminglogic
https://sider.ai/AI-video-shortener-s...