Drill 1: Change a value — LINQ in depth
Describe what would change if you edited one value.
What you will be able to do
- Describe what would change if you edited one value.
Practice task
Describe what would change if you edited one value.
record Course(int Id, string Name);
record Lesson(int CourseId, string Title, int Minutes);
var courses = new[]
{
new Course(1, "C#"),
new Course(2, "C"),
};
var lessons = new[]
{
new Lesson(1, "Variables", 12),
new Lesson(1, "Methods", 11),
new Lesson(2, "Pointers", 15),
new Lesson(2, "Structs", 14),
};
var query = lessons.Where(lesson => lesson.Minutes > 11);
var flat = courses
.SelectMany(course => lessons.Where(lesson => lesson.CourseId == course.Id))
.ToList();
var grouped = lessons
.GroupBy(lesson => lesson.CourseId)
.Select(group => new { CourseId = group.Key, Count = group.Count() })
.ToList();
var joined = courses
.Join(lessons,
course => course.Id,
lesson => lesson.CourseId,
(course, lesson) => course.Name + ": " + lesson.Title)
.ToList();
var materialised = query.ToList();Your turn
EasyWrite your answer
Describe what would change if you edited one value.
TEXT · starter
Your answer…Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.