My Code is as below
List<User> UserDetails = AllUser.Where(x => x.UserId == 5).ToList();
This Code will return all User with userID=5
and store it to my list , If All user have 5 record with UserId=5
, it will store all 5 record to UserDetail
, How can I only store the first row of the record instead of all 5, because the other 4 is just redundancy from AllUser
User UserDetails = AllUser.FirstOrDefault(x => x.UserId == 5);
You can use .First()
User UserDetails = AllUser.First(x => x.UserId == 5);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With