What is the difference between Select and SelectMany in LINQ?
Hello everyone! I started learning LINQ and can't understand the difference between Select and SelectMany methods. I read the documentation, but the examples are somewhat abstract.
I have a simple class:
```csharp
public class Student
{
public string Name { get; set; }
public List Grades { get; set; }
}
```
And a list of students:
```csharp
var students = new List
{
new Student { Name = "Ivan", Grades = new List { 5, 4, 3 } },
new Student { Name = "Maria", Grades = new List { 4, 5, 5 } }
};
```
When I write:
```csharp
var result = students.Select(s => s.Grades);
```
I get a collection of two lists. But what will happen with SelectMany? It seems like the same thing, but not quite. I tried:
```csharp
var result2 = students.SelectMany(s => s.Grades);
```
No answers yet.
Log in to leave an answer
Blogs