Lecture overview -- Keyboard shortcut: 'u'  Previous page: An overview of some LINQ Query Operators -- Keyboard shortcut: 'p'  Next page: How a LINQ Query Operation works -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Page 6 : 11
Object-oriented Programming in C#
An Introduction to LINQ
LINQ Query Operations vs List<T> methods.

Many important methods in List<T> mutate the list

The similar LINQ query operations are pure functions - they return a new modified copy of the list

  • Traversal of collections

    • List<T>:   list.ForEach(Action);

    • LINQ:   newList = list.Select(Func);

  • Removal form collections

    • List<T>:   list.RemoveAll(Predicate);

    • LINQ:   newList = list.Where(negated Predicate);

  • Appending collections

    • List<T>:   list.AddRange(otherList);

    • LINQ:   newList = list.Concat(otherList);

  • Reversing collections

    • List<T>:   list.Reverse();

    • LINQ:   newList = list.Reverse();

  • Sorting collections

    • List<T>:   list.Sort(comparerMethod);

    • LINQ:   sortedList = list.OrderBy(KeySelector);

Go to exerciseList og Linq?