For people who are new to LINQ, it is difficult to understand the difference between First, FirstOrDefault, Single, SingleOrDefault. In this blog, I will explain what to use and when. I will take a simple example to make you understand practically how these methods work. Consider a class Employee with properties as Id, Name, and Department. class Employee { public int Id { get ; set ; } public string Name { get ; set ; } public string Department{ get ; set ; } } I have a list of Employees: List<Employee> employeeList = new List<Employee>(){ new Employee() { Id = 1, Name = "Sunny" , Department = "Technical" }, new Employee() { Id=2, Name= "Pinki" , Department = "HR" }, new Employee() { Id=3, Name= "Tensy" , De...
Comments
Post a Comment