-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinq filter.linq
71 lines (63 loc) · 1.56 KB
/
linq filter.linq
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<Query Kind="Program" />
void Main()
{
List<X> x = PopulateX();
Print(x);
List<X> y = Query(x, 1, null, null, null);
Print(y);
}
List<X> Query(List<X> x, int? A, int? B, int? C, int? D)
{
return
(
from a in x
where
(A == null || a.A == A)
&& (B == null || a.B == B)
&& (C == null || a.C == C)
&& (D == null || a.D == D)
select a
).ToList();
}
void Print(List<X> x)
{
Console.WriteLine("Count: {0}", x.Count);
foreach(var y in x)
{
Console.WriteLine("{0} {1} {2} {3}", y.A, y.B, y.C, y.D);
}
}
List<X> PopulateX()
{
List<X> x = new List<X>();
x.Add(new X() { A=1, B=1, C=1, D=1 });
x.Add(new X() { A=1, B=1, C=1, D=2 });
x.Add(new X() { A=1, B=1, C=1, D=3 });
x.Add(new X() { A=1, B=1, C=1, D=4 });
x.Add(new X() { A=1, B=1, C=1, D=5 });
x.Add(new X() { A=1, B=1, C=1, D=6 });
x.Add(new X() { A=1, B=1, C=1, D=7 });
x.Add(new X() { A=1, B=1, C=2, D=1 });
x.Add(new X() { A=1, B=1, C=2, D=2 });
x.Add(new X() { A=1, B=1, C=2, D=3 });
x.Add(new X() { A=1, B=1, C=2, D=4 });
x.Add(new X() { A=2, B=1, C=1, D=1 });
x.Add(new X() { A=2, B=1, C=1, D=2 });
x.Add(new X() { A=2, B=1, C=1, D=3 });
x.Add(new X() { A=2, B=1, C=1, D=4 });
x.Add(new X() { A=2, B=1, C=1, D=5 });
x.Add(new X() { A=2, B=1, C=1, D=6 });
x.Add(new X() { A=2, B=1, C=1, D=7 });
x.Add(new X() { A=2, B=1, C=2, D=1 });
x.Add(new X() { A=2, B=1, C=2, D=2 });
x.Add(new X() { A=2, B=1, C=2, D=3 });
x.Add(new X() { A=2, B=1, C=2, D=4 });
return x;
}
class X
{
public int? A {get;set;}
public int? B {get;set;}
public int? C {get;set;}
public int? D {get;set;}
}