-
Notifications
You must be signed in to change notification settings - Fork 56
/
Conversion.cs
32 lines (28 loc) · 905 Bytes
/
Conversion.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Linq;
namespace StandardOperators
{
public static class Conversion
{
public static void HowNotToCastSequence()
{
IEnumerable<object> sequence = Course.Catalog.Select(c => (object)c);
var courseSequence = (IEnumerable<Course>)sequence; // InvalidCastException
}
public static void CastSequence()
{
IEnumerable<object> sequence = Course.Catalog.Select(c => (object)c);
var courseSequence = sequence.Cast<Course>();
}
public static void CreateLookup()
{
ILookup<string, Course> categoryLookup =
Course.Catalog.ToLookup(course => course.Category);
foreach (Course c in categoryLookup["MAT"])
{
Console.WriteLine(c.Title);
}
}
}
}