浅谈分组统计
2009-06-14 08:33:35 来源:WEB开发网最后,这个程序的输出如下所示:
==========> ForEach <============
Key ------Count Average----------
1 10,476 0.492122426354162
2 1,633,289 0.499917991099794
3 981,345 0.500446307804579
5 1,542,377 0.500567888024527
6 478,158 0.499376479287702
8 62,325 0.501552373474687
9 1,463,104 0.500270067230854
11 802,680 0.500518684820775
13 367,798 0.499572390413821
14 492,947 0.500767958524
16 2,403,053 0.500023199420802
17 248,208 0.499988049057847
--- ----------- -----------------
12 10,485,760 0.50018897689056
==========> Iterate <============
Key ------Count Average----------
1 10,476 0.492122426354162
2 1,633,289 0.499917991099794
3 981,345 0.500446307804579
5 1,542,377 0.500567888024527
6 478,158 0.499376479287702
8 62,325 0.501552373474687
9 1,463,104 0.500270067230854
11 802,680 0.500518684820775
13 367,798 0.499572390413821
14 492,947 0.500767958524
16 2,403,053 0.500023199420802
17 248,208 0.499988049057847
--- ----------- -----------------
12 10,485,760 0.50018897689056
==========> Linq <============
Key ------Count Average----------
1 10,476 0.492122426354162
2 1,633,289 0.499917991099794
3 981,345 0.500446307804579
5 1,542,377 0.500567888024527
6 478,158 0.499376479287702
8 62,325 0.501552373474687
9 1,463,104 0.500270067230854
11 802,680 0.500518684820775
13 367,798 0.499572390413821
14 492,947 0.500767958524
16 2,403,053 0.500023199420802
17 248,208 0.499988049057847
--- ----------- -----------------
12 10,485,760 0.50018897689056
这个程序中用到的 Tuple 类如下所示:
class Tuple<T1, T2>
{
public T1 Item1 { get; private set; }
public T2 Item2 { get; private set; }
public Tuple(T1 item1, T2 item2) { Item1 = item1; Item2 = item2; }
}
class Tuple<T1, T2, T3> : Tuple<T1, T2>
{
public T3 Item3 { get; private set; }
public Tuple(T1 item1, T2 item2, T3 item3) : base(item1, item2) { Item3 = item3; }
}
其实 .NET Framework 4.0 Base Class Library 中已经有 Tuple 类了。
更多精彩
赞助商链接