-
Notifications
You must be signed in to change notification settings - Fork 56
/
Subranges.cs
42 lines (37 loc) · 1.17 KB
/
Subranges.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
33
34
35
36
37
38
39
40
41
42
using System;
using System.Linq;
namespace StandardOperators
{
public static class Subranges
{
public static void SingleOperator()
{
var q = from course in Course.Catalog
where course.Category == "MAT" && course.Number == 101
select course;
Course geometry = q.Single();
}
public static void SingleOperatorWithPredicate()
{
Course geometry = Course.Catalog.Single(
course => course.Category == "MAT" && course.Number == 101);
}
public static void FirstOperator()
{
var q = from course in Course.Catalog
orderby course.Duration descending
select course;
Course longest = q.First();
}
public static void BadUseOfElementAt()
{
var mathsCourses = Course.Catalog.Where(c => c.Category == "MAT");
for (int i = 0; i < mathsCourses.Count(); ++i)
{
// Never do this!
Course c = mathsCourses.ElementAt(i);
Console.WriteLine(c.Title);
}
}
}
}