Let’s say you have a class like that: public class Student { public string Name { get; set; } public string Surname { get; set; } public DateTime DateCreated { get; set; } … } If you want to join the name values of that class then you can use the code below: using System.Linq […]
Tag: linq
What is the difference between HashSet and List in .net?
Unlike a List<> A HashSet is a List with no duplicate members. Because a HashSet is constrained to contain only unique entries, the internal structure is optimized for searching (compared with a list) – it is considerably faster Adding to a HashSet returns a boolean – false if addition fails due to already existing in […]
What is the difference between Select and SelectMany in Linq
The formal description for SelectMany() is: Projects each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence. SelectMany() flattens the resulting sequences into one sequence and invokes a result selector function on each element. The main difference is the result of each method while SelectMany() returns flattened results; Select() […]
Differences between FirstOrDefault and SingleOrDefault in LINQ
Whenever you use SingleOrDefault, you clearly state that the query should result in at most a single result. On the other hand, when FirstOrDefault is used, the query can return any amount of results but you state that you only want the first one. If your result set returns 0 records: Single throws an exception First throws an exception SingleOrDefault returns the default […]
What is the difference between IQueryable and IEnumerable?
That StackOverflow answer so far is the best one I have ever seen: This is an excellent video on youtube which demonstrates how these interfaces differ, worth a watch. Below goes a long descriptive answer to it. The first important point to remember is IQueryable interface inherits from IEnumerable, so whatever IEnumerable can do, IQueryable can also do. There are many differences […]