IEnumerable<T>:lamada表达式的根基,也是泛型集合操作的基础.using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;namespace System.Linq
{
    // 摘要:
    //     提供一组用于查询实现 System.Collections.Generic.IEnumerable<T> 的对象的 static(在 Visual
    //     Basic 中为 Shared)方法。
    public static class Enumerable
    {
        // 摘要:
        //     对序列应用累加器函数。
        //
        // 参数:
        //   source:
        //     要聚合的 System.Collections.Generic.IEnumerable<T>。
        //
        //   func:
        //     要对每个元素调用的累加器函数。
        //
        // 类型参数:
        //   TSource:
        //     source 中的元素的类型。
        //
        // 返回结果:
        //     累加器的最终值。
        //
        // 异常:
        //   System.ArgumentNullException:
        //     source 或 func 为 null。
        //
        //   System.InvalidOperationException:
        //     source 中不包含任何元素。
        public static TSource Aggregate<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TSource> func); //......    }
}
之间的接口关系图如下:
-----------------------------------------------
[1]IEnumerable<T> : IEnumerable{IEnumerator<T>}
[2]IEnumerable{IEnumerator}
-----------------------------------------------
[3]IEnumerator<T> : IDisposable, IEnumerator
[4]IEnumerator
-----------------------------------------------
[5]IDisposable

解决方案 »

  1.   

    常用扩展方法如下:静态方法 说明
    Aggregate() 对集合应用累加器函数
    All<T>() 判断集合中的所有元素是否满足条件
    Any() 判断集合中是否存在满足条件的元素
    AsEnumerable<T>() 将数据源转换为IEnumerable<T>类型对象
    Average() 计算集合中的平均值
    Cast<T>() 将集合中的元素转换为指定的类型,并返回新的集合
    Concat<T>() 连接两个集合
    Contains() 判断集合中是否饱饭指定的元素
    Count() 集合中的元素数量
    DefaultIfEmpty() 返回IEnumerable<T>类型的序列。如果序列为空,则返回只包含一个元素的序列
    Distinct() 去掉集合中的重复元素
    ElementAt() 获取指定索引处的元素
    ElementAtOrDefault() 获取指定索引处的元素,如果元素不存在,则返回默认值
    Empty() 返回一个IEnumerable<T>类型的空集合
    Except() 计算两个集合的差集
    First() 获取集合中的第一个元素
    FirstOrDefault() 获取集合中的第一个元素,如果未找到该元素,则返回默认值
    GroupBy() 对集合中的元素进行分组
    GroupJoin() 连接两个集合,并进行分组
    Intersect() 计算两个集合的交集
    Join() 连接两个集合
    Last() 获取集合中的最后一个元素
    LastOrDefault() 获取集合中的最后一个元素,如果未找到该元素,则返回默认值
    LongCount() 集合中的元素数量
    Max() 获取集合中的最大元素
    Min() 获取集合中的最小元素
    OfType<T>() 根据指定类型筛选相应的元素
    OrderBy() 对元素进行升序排序
    OrderByDescending() 对元素进行降序排序
    Range() 返回指定范围内的整数的集合
    Repeat<T>() 返回一个包含重复元素的序列
    Reverse<T>() 反转集合中元素的顺序
    Select() 将集合中的元素投影到新的集合中
    SelectMany() 将集合中的元素投影到新的集合中,并将结果合并为一个集合
    SequenceEqual() 判断两个集合是否想的
    Single() 获取集合中唯一的元素
    SingleOrDefault() 获取集合中唯一的元素,如果元素不存在,则返回默认值
    Skip<T>() 跳过集合中指定的元素,并返回该集合剩余的元素
    SkipWhile() 跳过集合中指定条件的元素,并返回该集合剩余的元素
    Sum() 计算集合中元素的和
    Take<T>() 提取集合中指定的元素
    TakeWhile() 提取集合中指定条件的元素
    ThenBy() 按次要关键字对元素进行升序排序
    ThenByDescending() 按次要关键字对元素进行降序排序
    ToArray<T>() 创建一个数组
    ToDictionary() 创建一个Dictionary<TKey,TValue>对象
    ToList<T>() 创建一个List<T>对象
    ToLookup() 创建一个泛型Lookup<TKey,TElement>对象
    Union() 计算两个集合的并集
    Where() 指定筛选元素的条件
    帮忙顶一下,谢谢...
      

  2.   

    借楼主的帖子发下我的问题,如有打扰见谅 http://topic.csdn.net/u/20090825/15/71d11f43-08a6-4f04-8152-a0737dddd2d4.html?seed=1079724398&r=59322234#r_59322234
      

  3.   

    虽然看不懂,但仍友情支持
    □□□■□□□□□■□□□□□□□□□□□□■□□□■□□□□□□
    □□□■□□■■■■■■■■□□□□□□□□■□□□□■□□□□□
    □□□■□□□□□□□□□□□□□□□□□■□□□□□■□□□□□
    ■■■■■■□■□□□□■□□□□□□□■□□□□□□□■□□□□
    □□□■□□□□■□□■□□□□□□□■□□□□□□□□□■□□□
    □□□■□■■■■■■■■■■□□□■□□□□□□□□□□□■□□
    □□□■□□□□□■□□□□□□□■□□■■■■■■■■□□□■□
    □□□■■□□□□■□□□□□□□□□□□□■□□□□■□□□□□
    □□■■□■■■■■■■■■■□□□□□□□■□□□□■□□□□□
    ■■□■□□□□■□□□■□□□□□□□□□■□□□□■□□□□□
    □□□■□□□■□□□□■□□□□□□□□■□□□□□■□□□□□
    □□□■□□□□■□□■□□□□□□□□□■□□□□□■□□□□□
    □□□■□□□□□■■□□□□□□□□□■□□□□□□■□□□□□
    □■□■□□□■■□□■■□□□□□□■□□□□■□■□□□□□□
    □□■□□■■□□□□□□■□□□□■□□□□□□■□□□□□□□
    □□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□
    [DYLIKE TEXT TO IMAGE-TEXT]
      

  4.   

    @hrbwgs1111
    没关系@dylike
    估证不会有分了,这个用作"记事本"了再来个补全版本
    NO 扩展方法 说明
    1 Aggregate 对序列应用累加器函数。
    2 All 确定序列中的所有元素是否满足条件。
    3 Any 确定序列是否包含任何元素。
    4 AsEnumerable 返回类型为 System.Collections.Generic.IEnumerable<T> 的输入。
    5 Average 计算可以为 null 的 System.Decimal 值序列的平均值。
    6 Cast 将 System.Collections.IEnumerable 的元素转换为指定的类型。
    7 Concat 连接两个序列。
    8 Contains 通过使用默认的相等比较器确定序列是否包含指定的元素。
    9 Count 返回序列中的元素数量。
    10 DefaultIfEmpty 返回指定序列的元素;如果序列为空,则返回单一实例集合中的类型参数的默认值。
    11 Distinct 通过使用默认的相等比较器对值进行比较返回序列中的非重复元素。
    12 ElementAt 返回序列中指定索引处的元素。
    13 ElementAtOrDefault 返回序列中指定索引处的元素;如果索引超出范围,则返回默认值。
    14 Empty 返回一个具有指定的类型参数的空 System.Collections.Generic.IEnumerable<T>。
    15 Except 通过使用默认的相等比较器对值进行比较生成两个序列的差集。
    16 First 返回序列中的第一个元素。
    17 FirstOrDefault 返回序列中的第一个元素;如果序列中不包含任何元素,则返回默认值。
    18 TSource 根据指定的键选择器函数对序列中的元素进行分组。
    19 GroupBy 根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。
    20 TElement 根据指定的键选择器函数对序列中的元素进行分组,并且通过使用指定的函数对每个组中的元素进行投影。
    21 GroupJoin 基于键相等对两个序列的元素进行关联并对结果进行分组。使用默认的相等比较器对键进行比较。
    22 Intersect 通过使用默认的相等比较器对值进行比较生成两个序列的交集。
    23 Join 基于匹配键对两个序列的元素进行关联。使用默认的相等比较器对键进行比较。
    24 Last 返回序列的最后一个元素。
    25 LastOrDefault 返回序列中的最后一个元素;如果序列中不包含任何元素,则返回默认值。
    26 LongCount 返回一个 System.Int64,表示序列中的元素的总数量。
    27 Max 返回可以为 null 的 System.Decimal 值序列中的最大值。
    28 Min 返回 System.Decimal 值(可空)序列中的最小值。
    29 OfType 根据指定类型筛选 System.Collections.IEnumerable 的元素。
    30 OrderBy 根据键按升序对序列的元素排序。
    31 OrderByDescending 根据键按降序对序列的元素排序。
    32 Range 生成指定范围内的整数的序列。
    33 Repeat 生成包含一个重复值的序列。
    34 Reverse 反转序列中元素的顺序。
    35 Select 通过合并元素的索引将序列的每个元素投影到新表中。
    36 SelectMany 将序列的每个元素投影到 System.Collections.Generic.IEnumerable<T> 并将结果序列合并为一个序列。
    37 SequenceEqual 通过使用相应类型的默认相等比较器对序列的元素进行比较,以确定两个序列是否相等。
    38 Single 返回序列的唯一元素;如果该序列并非恰好包含一个元素,则会引发异常。
    39 SingleOrDefault 返回序列中的唯一元素;如果该序列为空,则返回默认值;如果该序列包含多个元素,此方法将引发异常。
    40 Skip 跳过序列中指定数量的元素,然后返回剩余的元素。
    41 SkipWhile 只要满足指定的条件,就跳过序列中的元素,然后返回剩余元素。
    42 Sum 计算可以为 null 的 System.Decimal 值序列之和。
    43 Take 从序列的开头返回指定数量的连续元素。
    44 TakeWhile 只要满足指定的条件,就会返回序列的元素。
    45 ThenBy 根据某个键按升序对序列中的元素执行后续排序。
    46 ThenByDescending 根据某个键按降序对序列中的元素执行后续排序。
    47 ToArray 从 System.Collections.Generic.IEnumerable<T> 创建一个数组。
    48 TSource 根据指定的键选择器函数,从 System.Collections.Generic.IEnumerable<T> 创建一个 System.Collections.Generic.Dictionary<TKey,TValue>。
    49 TElement 根据指定的键选择器和元素选择器函数,从 System.Collections.Generic.IEnumerable<T> 创建一个 System.Collections.Generic.Dictionary<TKey,TValue>。
    50 ToList 从 System.Collections.Generic.IEnumerable<T> 创建一个 System.Collections.Generic.List<T>。
    51 Union 通过使用默认的相等比较器生成两个序列的并集。
    52 Where 基于谓词筛选值序列。
      

  5.   

    这个是全整版的/下面继续lamada表达式之旅NO 扩展方法 说明
    1 Aggregate 对序列应用累加器函数。
    2 Aggregate 对序列应用累加器函数。将指定的种子值用作累加器初始值。
    3 Aggregate 对序列应用累加器函数。将指定的种子值用作累加器的初始值,并使用指定的函数选择结果值。
    4 All 确定序列中的所有元素是否满足条件。
    5 Any 确定序列是否包含任何元素。
    6 Any 确定序列中的任何元素是否都满足条件。
    7 AsEnumerable 返回类型为 System.Collections.Generic.IEnumerable<T> 的输入。
    8 Average 计算可以为 null 的 System.Decimal 值序列的平均值。
    9 Average 计算 System.Decimal 值序列的平均值。
    10 Average 计算可以为 null 的 System.Double 值序列的平均值。
    11 Average 计算 System.Double 值序列的平均值。
    12 Average 计算可以为 null 的 System.Single 值序列的平均值。
    13 Average 计算 System.Single 值序列的平均值。
    14 Average 计算可以为 null 的 System.Int32 值序列的平均值。
    15 Average 计算 System.Int32 值序列的平均值。
    16 Average 计算可以为 null 的 System.Int64 值序列的平均值。
    17 Average 计算 System.Int64 值序列的平均值。
    18 Average 计算可以为 null 的 System.Decimal 值序列的平均值,该值可通过调用输入序列的每个元素的转换函数获取。
    19 Average 计算 System.Decimal 值序列的平均值,该值可通过调用输入序列的每个元素的转换函数获取。
    20 Average 计算可以为 null 的 System.Double 值序列的平均值,该值可通过调用输入序列的每个元素的转换函数获取。
    21 Average 计算 System.Double 值序列的平均值,该值可通过调用输入序列的每个元素的转换函数获取。
    22 Average 计算可以为 null 的 System.Single 值序列的平均值,该值可通过调用输入序列的每个元素的转换函数获取。
    23 Average 计算 System.Single 值序列的平均值,该值可通过调用输入序列的每个元素的转换函数获取。
    24 Average 计算可以为 null 的 System.Int32 值序列的平均值,该值可通过调用输入序列的每个元素的转换函数获取。
    25 Average 计算 System.Int32 值序列的平均值,该值可通过调用输入序列的每个元素的转换函数获取。
    26 Average 计算可以为 null 的 System.Int64 值序列的平均值,该值可通过调用输入序列的每个元素的转换函数获取。
    27 Average 计算 System.Int64 值序列的平均值,该值可通过调用输入序列的每个元素的转换函数获取。
    28 Cast 将 System.Collections.IEnumerable 的元素转换为指定的类型。
    29 Concat 连接两个序列。
    30 Contains 通过使用默认的相等比较器确定序列是否包含指定的元素。
    31 Contains 通过使用指定的 System.Collections.Generic.IEqualityComparer<T> 确定序列是否包含指定的元素。
    32 Count 返回序列中的元素数量。
    33 Count 返回一个数字,表示在指定的序列中满足条件的元素数量。
    34 DefaultIfEmpty 返回指定序列的元素;如果序列为空,则返回单一实例集合中的类型参数的默认值。
    35 DefaultIfEmpty 返回指定序列中的元素;如果序列为空,则返回单一实例集合中的指定值。
    36 Distinct 通过使用默认的相等比较器对值进行比较返回序列中的非重复元素。
    37 Distinct 通过使用指定的 System.Collections.Generic.IEqualityComparer<T> 对值进行比较返回序列中的非重复元素。
    38 ElementAt 返回序列中指定索引处的元素。
    39 ElementAtOrDefault 返回序列中指定索引处的元素;如果索引超出范围,则返回默认值。
    40 Empty 返回一个具有指定的类型参数的空 System.Collections.Generic.IEnumerable<T>。
    41 Except 通过使用默认的相等比较器对值进行比较生成两个序列的差集。
    42 Except 通过使用指定的 System.Collections.Generic.IEqualityComparer<T> 对值进行比较产生两个序列的差集。
    43 First 返回序列中的第一个元素。
    44 First 返回序列中满足指定条件的第一个元素。
    45 FirstOrDefault 返回序列中的第一个元素;如果序列中不包含任何元素,则返回默认值。
    46 FirstOrDefault 返回序列中满足条件的第一个元素;如果未找到这样的元素,则返回默认值。
    47 TSource>> 根据指定的键选择器函数对序列中的元素进行分组。
    48 GroupBy 根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。
    49 TElement>> 根据指定的键选择器函数对序列中的元素进行分组,并且通过使用指定的函数对每个组中的元素进行投影。
    50 TSource>> 根据指定的键选择器函数对序列中的元素进行分组,并使用指定的比较器对键进行比较。
    51 GroupBy 根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。通过使用指定的比较器对键进行比较。
    52 GroupBy 根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。通过使用指定的函数对每个组的元素进行投影。
    53 TElement>> 根据键选择器函数对序列中的元素进行分组。通过使用比较器对键进行比较,并且通过使用指定的函数对每个组的元素进行投影。
    54 GroupBy 根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值。通过使用指定的比较器对键值进行比较,并且通过使用指定的函数对每个组的元素进行投影。
    55 GroupJoin 基于键相等对两个序列的元素进行关联并对结果进行分组。使用默认的相等比较器对键进行比较。
    56 GroupJoin 基于键相等对两个序列的元素进行关联并对结果进行分组。使用指定的 System.Collections.Generic.IEqualityComparer<T>
    57 Intersect 通过使用默认的相等比较器对值进行比较生成两个序列的交集。
    58 Intersect 通过使用指定的 System.Collections.Generic.IEqualityComparer<T> 对值进行比较以生成两个序列的交集。
    59 Join 基于匹配键对两个序列的元素进行关联。使用默认的相等比较器对键进行比较。
    60 Join 基于匹配键对两个序列的元素进行关联。使用指定的 System.Collections.Generic.IEqualityComparer<T> 对键进行比较。
    61 Last 返回序列的最后一个元素。
    62 Last 返回序列中满足指定条件的最后一个元素。
    63 LastOrDefault 返回序列中的最后一个元素;如果序列中不包含任何元素,则返回默认值。
    64 LastOrDefault 返回序列中满足条件的最后一个元素;如果未找到这样的元素,则返回默认值。
    65 LongCount 返回一个 System.Int64,表示序列中的元素的总数量。
    66 LongCount 返回一个 System.Int64,表示序列中满足条件的元素的数量。
    67 Max 返回可以为 null 的 System.Decimal 值序列中的最大值。
    68 Max 返回 System.Decimal 值序列中的最大值。
    69 Max 返回可以为 null 的 System.Double 值序列中的最大值。
    70 Max 返回 System.Double 值序列中的最大值。
    71 Max 返回可以为 null 的 System.Single 值序列中的最大值。
    72 Max 返回 System.Single 值序列中的最大值。
    73 Max 返回可以为 null 的 System.Int32 值序列中的最大值。
    74 Max 返回 System.Int32 值序列中的最大值。
    75 Max 返回可以为 null 的 System.Int64 值序列中的最大值。
    76 Max 返回 System.Int64 值序列中的最大值。
    77 Max 返回泛型序列中的最大值。
    78 Max 调用序列的每个元素上的转换函数并返回可空 System.Decimal 的最大值。
    79 Max 调用序列的每个元素上的转换函数并返回最大 System.Decimal 值。
    80 Max 调用序列的每个元素上的转换函数并返回可空 System.Double 的最大值。
    81 Max 调用序列的每个元素上的转换函数并返回最大 System.Double 值。
    82 Max 调用序列的每个元素上的转换函数并返回可空 System.Single 的最大值。
    83 Max 调用序列的每个元素上的转换函数并返回最大 System.Single 值。
    84 Max 调用序列的每个元素上的转换函数并返回可空 System.Int32 的最大值。
    85 Max 调用序列的每个元素上的转换函数并返回最大 System.Int32 值。
    86 Max 调用序列的每个元素上的转换函数并返回可空 System.Int64 的最大值。
    87 Max 调用序列的每个元素上的转换函数并返回最大 System.Int64 值。
    88 Max 调用泛型序列的每个元素上的转换函数并返回最大结果值。
    89 Min 返回 System.Decimal 值(可空)序列中的最小值。
    90 Min 返回 System.Decimal 值序列中的最小值。
    91 Min 返回 System.Double 值(可空)序列中的最小值。
    92 Min 返回 System.Double 值序列中的最小值。
    93 Min 返回 System.Single 值(可空)序列中的最小值。
    94 Min 返回 System.Single 值序列中的最小值。
    95 Min 返回 System.Int32 值(可空)序列中的最小值。
    96 Min 返回 System.Int32 值序列中的最小值。
    97 Min 返回 System.Int64 值(可空)序列中的最小值。
    98 Min 返回 System.Int64 值序列中的最小值。
    99 Min 返回泛型序列中的最小值。
    100 Min 调用序列的每个元素上的转换函数并返回可空 System.Decimal 的最小值。
    101 Min 调用序列的每个元素上的转换函数并返回最小 System.Decimal 值。
    102 Min 调用序列的每个元素上的转换函数并返回可空 System.Double 的最小值。
    103 Min 调用序列的每个元素上的转换函数并返回最小 System.Double 值。
    104 Min 调用序列的每个元素上的转换函数并返回可空 System.Single 的最小值。
    105 Min 调用序列的每个元素上的转换函数并返回最小 System.Single 值。
    106 Min 调用序列的每个元素上的转换函数并返回可空 System.Int32 的最小值。
    107 Min 调用序列的每个元素上的转换函数并返回最小 System.Int32 值。
    108 Min 调用序列的每个元素上的转换函数并返回可空 System.Int64 的最小值。
    109 Min 调用序列的每个元素上的转换函数并返回最小 System.Int64 值。
    110 Min 调用泛型序列的每个元素上的转换函数并返回最小结果值。
    111 OfType 根据指定类型筛选 System.Collections.IEnumerable 的元素。
    112 OrderBy 根据键按升序对序列的元素排序。
    113 OrderBy 使用指定的比较器按升序对序列的元素排序。
    114 OrderByDescending 根据键按降序对序列的元素排序。
    115 OrderByDescending 使用指定的比较器按降序对序列的元素排序。
    116 Range 生成指定范围内的整数的序列。
    117 Repeat 生成包含一个重复值的序列。
    118 Reverse 反转序列中元素的顺序。
    119 Select 通过合并元素的索引将序列的每个元素投影到新表中。
    120 Select 将序列中的每个元素投影到新表中。
    121 SelectMany 将序列的每个元素投影到 System.Collections.Generic.IEnumerable<T> 并将结果序列合并为一个序列。
    122 SelectMany 将序列的每个元素投影到 System.Collections.Generic.IEnumerable<T>,并将结果序列合并为一个序列。每个源元素的索引用于该元素的投影表。
    123 SelectMany 将序列的每个元素投影到 System.Collections.Generic.IEnumerable<T>,并将结果序列合并为一个序列,并对其中每个元素调用结果选择器函数。
    124 SelectMany 将序列的每个元素投影到 System.Collections.Generic.IEnumerable<T>,并将结果序列合并为一个序列,并对其中每个元素调用结果选择器函数。每个源元素的索引用于该元素的中间投影表。
    125 SequenceEqual 通过使用相应类型的默认相等比较器对序列的元素进行比较,以确定两个序列是否相等。
    126 SequenceEqual 使用指定的 System.Collections.Generic.IEqualityComparer<T> 对两个序列的元素进行比较,以确定序列是否相等。
    127 Single 返回序列的唯一元素;如果该序列并非恰好包含一个元素,则会引发异常。
    128 Single 返回序列中满足指定条件的唯一元素;如果有多个这样的元素存在,则会引发异常。
    129 SingleOrDefault 返回序列中的唯一元素;如果该序列为空,则返回默认值;如果该序列包含多个元素,此方法将引发异常。
    130 SingleOrDefault 返回序列中满足指定条件的唯一元素;如果这类元素不存在,则返回默认值;如果有多个元素满足该条件,此方法将引发异常。
    131 Skip 跳过序列中指定数量的元素,然后返回剩余的元素。
    132 SkipWhile 只要满足指定的条件,就跳过序列中的元素,然后返回剩余元素。
    133 SkipWhile 只要满足指定的条件,就跳过序列中的元素,然后返回剩余元素。将在谓词函数的逻辑中使用元素的索引。
    134 Sum 计算可以为 null 的 System.Decimal 值序列之和。
    135 Sum 计算 System.Decimal 值序列之和。
    136 Sum 计算可以为 null 的 System.Double 值序列之和。
    137 Sum 计算 System.Double 值序列之和。
    138 Sum 计算可以为 null 的 System.Single 值序列之和。
    139 Sum 计算 System.Single 值序列之和。
    140 Sum 计算可以为 null 的 System.Int32 值序列之和。
    141 Sum 计算 System.Int32 值序列之和。
    142 Sum 计算可以为 null 的 System.Int64 值序列之和。
    143 Sum 计算 System.Int64 值序列之和。
    144 Sum 计算可以为 null 的 System.Decimal 值序列的和,这些值是通过对输入序列中的每个元素调用转换函数得来的。
    145 Sum 计算 System.Decimal 值序列的和,这些值是通过对输入序列中的每个元素调用转换函数得来的。
    146 Sum 计算可以为 null 的 System.Double 值序列的和,这些值是通过对输入序列中的每个元素调用转换函数得来的。
    147 Sum 计算 System.Double 值序列的和,这些值是通过对输入序列中的每个元素调用转换函数得来的。
    148 Sum 计算可以为 null 的 System.Single 值序列的和,这些值是通过对输入序列中的每个元素调用转换函数得来的。
    149 Sum 计算 System.Single 值序列的和,这些值是通过对输入序列中的每个元素调用转换函数得来的。
    150 Sum 计算可以为 null 的 System.Int32 值序列的和,这些值是通过对输入序列中的每个元素调用转换函数得来的。
    151 Sum 计算 System.Int32 值序列的和,这些值是通过对输入序列中的每个元素调用转换函数得来的。
    152 Sum 计算可以为 null 的 System.Int64 值序列的和,这些值是通过对输入序列中的每个元素调用转换函数得来的。
    153 Sum 计算 System.Int64 值序列的和,这些值是通过对输入序列中的每个元素调用转换函数得来的。
    154 Take 从序列的开头返回指定数量的连续元素。
    155 TakeWhile 只要满足指定的条件,就会返回序列的元素。
    156 TakeWhile 只要满足指定的条件,就会返回序列的元素。将在谓词函数的逻辑中使用元素的索引。
    157 ThenBy 根据某个键按升序对序列中的元素执行后续排序。
    158 ThenBy 使用指定的比较器按升序对序列中的元素执行后续排序。
    159 ThenByDescending 根据某个键按降序对序列中的元素执行后续排序。
    160 ThenByDescending 使用指定的比较器按降序对序列中的元素执行后续排序。
    161 ToArray 从 System.Collections.Generic.IEnumerable<T> 创建一个数组。
    162 TSource> 根据指定的键选择器函数,从 System.Collections.Generic.IEnumerable<T> 创建一个 System.Collections.Generic.Dictionary<TKey,TValue>。
    163 TElement> 根据指定的键选择器和元素选择器函数,从 System.Collections.Generic.IEnumerable<T> 创建一个 System.Collections.Generic.Dictionary<TKey,TValue>。
    164 TSource> 根据指定的键选择器函数和键比较器,从 System.Collections.Generic.IEnumerable<T> 创建一个 System.Collections.Generic.Dictionary<TKey,TValue>。
    165 TElement> 根据指定的键选择器函数、比较器和元素选择器函数从 System.Collections.Generic.IEnumerable<T> 创建一个 System.Collections.Generic.Dictionary<TKey,TValue>。
    166 ToList 从 System.Collections.Generic.IEnumerable<T> 创建一个 System.Collections.Generic.List<T>。
    167 TSource> 根据指定的键选择器函数,从 System.Collections.Generic.IEnumerable<T> 创建一个 System.Linq.Lookup<TKey,TElement>。
    168 TElement> 根据指定的键选择器和元素选择器函数,从 System.Collections.Generic.IEnumerable<T> 创建一个 System.Linq.Lookup<TKey,TElement>。
    169 TSource> 根据指定的键选择器函数和键比较器,从 System.Collections.Generic.IEnumerable<T> 创建一个 System.Linq.Lookup<TKey,TElement>。
    170 TElement> 根据指定的键选择器函数、比较器和元素选择器函数,从 System.Collections.Generic.IEnumerable<T> 创建一个
    171 Union 通过使用默认的相等比较器生成两个序列的并集。
    172 Union 通过使用指定的 System.Collections.Generic.IEqualityComparer<T> 生成两个序列的并集。
    173 Where 基于谓词筛选值序列。
    174 Where 基于谓词筛选值序列。将在谓词函数的逻辑中使用每个元素的索引。
      

  6.   

    借用"老赵"的例子,show一下lamada表达式的强大.
    给坛子里初识或尚未识lamada的朋友提提兴趣...[1]案例A
    写一个方法,输入一个表示整型的字符串列表,
    并返回一个列表,包含其中偶数的平方,
    并且需要按照平方后的结果排序”。普通版:
    static List<int> GetSquaresOfPositive(List<string> strList)
    {
        List<int> intList = new List<int>();
        foreach (var s in strList) intList.Add(Int32.Parse(s));    List<int> evenList = new List<int>();
        foreach (int i in intList)
        {
            if (i % 2 == 0) evenList.Add(i);
        }    List<int> squareList = new List<int>();
        foreach (int i in evenList) squareList.Add(i * i);    squareList.Sort();
        return squareList;
    }
    lamada版
    static List<int> GetSquaresOfPositiveByLambda(List<string> strList)
    {
        return strList
            .Select(s => Int32.Parse(s)) // 转成整数
            .Where(i => i % 2 == 0) // 找出所有偶数
            .Select(i => i * i) // 算出每个数的平方
            .OrderBy(i => i) // 按照元素自身排序
            .ToList(); // 构造一个List
    }
    [2]案例B
    列出所有的关键字,
    根据其首字母进行分组,
    并且要求对每组内部的关键字进行排序普通版(使用闭包的经典场景)
    static Dictionary<char, List<string>> GetIndex(IEnumerable<string> keywords)
    {
        // 定义字典
        var result = new Dictionary<char, List<string>>();    // 填充字典
        foreach (var kw in keywords)
        {
            var firstChar = kw[0];
            List<string> groupKeywords;        if (!result.TryGetValue(firstChar, out groupKeywords))
            {
                groupKeywords = new List<string>();
                result.Add(firstChar, groupKeywords);
            }        groupKeywords.Add(kw);
        }    // 为每个分组排序
        foreach (var groupKeywords in result.Values)
        {
            groupKeywords.Sort();
        }    return result;
    }
    lamada版
    static Dictionary<char, List<string>> GetIndexByLambda(IEnumerable<string> keywords)
    {
        return keywords
            .GroupBy(k => k[0]) // 按照首字母分组
            .ToDictionary( // 构造字典
                g => g.Key, // 以每组的Key作为键
                g => g.OrderBy(k => k).ToList()); // 对每组排序并生成列表
    }
    [3]案例C
    要求算一任意长度字符串中不同的字符以及它的个数。 
    var values = "abcdefgabc"
        .GroupBy(c => c)
        .Select(g => String.Format("{0}, {1}", g.Key, g.Count()))
        .ToArray();
    Array.ForEach(values, v => Console.WriteLine(v));
    [3]案例D
    把一段字符串用“右起竖排”的古文格式输出。 
    static void Print(string text, int offset)
    {
        text
            .Select((c, i) => new { Char = c, Index = i })
            .GroupBy(c => c.Index % offset, c => c)
            .ForEach(g => Console.WriteLine(g.Reverse().Join("|")));
    }调用
    Print("床前明月光疑似地上霜举头望明月低头思故乡", 5);
    输出
    低|举|疑|床
    头|头|似|前
    思|望|地|明
    故|明|上|月
    乡|月|霜|光
      

  7.   

    [@]2009/08/28 
    [%]继续集合看集合先看接口/泛型的
    System.Collections.Generic
    [!]关键查看接口的继承关系========================
    System.Collections(接口)
    ========================
    System.Collections.Generic.IComparer<T>
    System.Collections.Generic.IEqualityComparer<T>
    System.Collections.Generic.IEnumerator<T>
    -----------------------------------------
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.Generic.IList<T>
    -----------------------------------------
    System.Collections.Generic.IDictionary<TKey,TValue>========================
    System.Collections(类)
    ========================
    System.Collections.Generic.Comparer<T>
    System.Collections.Generic.EqualityComparer<T>
    System.Collections.Generic.KeyNotFoundException
    -----------------------------------------
    System.Collections.Generic.List<T>
    System.Collections.Generic.LinkedList<T>
    System.Collections.Generic.LinkedListNode<T>
    System.Collections.Generic.Queue<T>
    System.Collections.Generic.Stack<T>
    System.Collections.Generic.HashSet<T>
    -----------------------------------------
    System.Collections.Generic.Dictionary<TKey,TValue>
    System.Collections.Generic.Dictionary<TKey,TValue>.KeyCollection
    System.Collections.Generic.Dictionary<TKey,TValue>.ValueCollection
    System.Collections.Generic.SortedList<TKey,TValue>
    System.Collections.Generic.SortedDictionary<TKey,TValue>
    System.Collections.Generic.SortedDictionary<TKey,TValue>.KeyCollection
    System.Collections.Generic.SortedDictionary<TKey,TValue>.ValueCollection
    -----------------------------------------
    System.Collections.Generic.SynchronizedReadOnlyCollection<T>
    System.Collections.Generic.SynchronizedCollection<T>
    System.Collections.Generic.SynchronizedKeyedCollection<K, T>*
    -----------------------------------------
    System.Collections.Generic.KeyedByTypeCollection<TItem>*========================
    System.Collections(结构)
    ========================
    System.ValueType
    -----------------------------------------
    System.Collections.Generic.List<T>.Enumerator
    System.Collections.Generic.LinkedList<T>.Enumerator
    System.Collections.Generic.Queue<T>.Enumerator
    System.Collections.Generic.Stack<T>.Enumerator
    System.Collections.Generic.HashSet<T>.Enumerator
    -----------------------------------------
    System.Collections.Generic.KeyValuePair<TKey,TValue>
    System.Collections.Generic.Dictionary<TKey,TValue>.Enumerator
    System.Collections.Generic.Dictionary<TKey,TValue>.KeyCollection.Enumerator
    System.Collections.Generic.Dictionary<TKey,TValue>.ValueCollection.Enumerator
    System.Collections.Generic.SortedDictionary<TKey,TValue>.Enumerator
    System.Collections.Generic.SortedDictionary<TKey,TValue>.KeyCollection.Enumerator
    System.Collections.Generic.SortedDictionary<TKey,TValue>.ValueCollection.Enumerator
      

  8.   

    这个是.net 3.5以上的么???
      

  9.   

    或许,楼主详细谈谈linq和lamada这两个东西
      

  10.   

    顶[align=center]****************************************************************
                今天回帖带祝福,七夕情人节快乐~^_^
    ****************************************************************[/align]
      

  11.   

    我们先来看一下"迭代程序/foreach"的实现.
    依赖于以下两组接口(普通版和泛型版略有不同)普版:
    public interface IEnumerable 
    {
       IEnumerator GetEnumerator();
    }public interface IEnumerator 
    {
       object Current{get;}
       bool MoveNext();
       void Reset();
    }
    泛版:
    public interface IEnumerable<ItemType>
    {   
       IEnumerator<ItemType> GetEnumerator();
    } public interface IEnumerator<ItemType> : IDisposable
    {
       ItemType Current{get;}
       bool MoveNext();
    }注:IEnumerator不同于IEnumerator<ItemType>
    泛版的是从IDisposable派生而来的,并且没有Reset方法。
      

  12.   

    下面我想看:
    yield return到底干了些什么?
    明日里我只知道用,只知道:
    返回的是IEnumerator/IEnumerator<T>
    这不过是一个接口,lamada表达式基本上返回的全是这个.
    他真正的返回类型是什么???注:以下上伪码,并不能编译通过
    using System;
    using System.Collections;
    using System.Collections.Generic;namespace MyCollectionA//转换前
    {
        public class MyCollection : IEnumerable<string>
        {
            public IEnumerator<string> GetEnumerator()
            {
                //Some iteration code that uses yield return 
            }
        }
    }namespace MyCollectionB//转换后
    {
        public class MyCollection : IEnumerable<string>
        {
           public virtual IEnumerator<string> GetEnumerator()
           {
              GetEnumerator_0003__IEnumeratorImpl impl;
              impl = new GetEnumerator_0003__IEnumeratorImpl();
              impl._this = this;
              return impl; 
           }       private class GetEnumerator_0003__IEnumeratorImpl:IEnumerator<string>,IDisposable
           {
              public MyCollection _this; // Back reference to the collection
              string __current;
              // state machine members go here 
              string IEnumerator<string>.Current
              {
                 get
                 {
                    return __current;
                 }
              }
              bool IEnumerator<string>.MoveNext()
              {
                 //State machine management 
              }          void IDisposable.Dispose()
              {
                 //State machine cleanup if required  
              }
           }
        }
    }当编译器遇到这种带有 yield return 语句的类成员时,
    它会插入一个名为 GetEnumerator$<random unique number>__IEnumeratorImpl 的嵌套类的定义。
    嵌套类实现了从类成员返回的相同 IEnumerable 接口。
    编译器使用一个实例化的嵌套类型来代替类成员中的代码,
    将一个指向集合的引用赋给嵌套类的 <this> 成员变量。
    实际上,该嵌套类是一个提供了 IEnumerator 的实现的类。
      

  13.   

    再搞一个能运行,
    好好体会一下:using System;
    using System.Collections;public class List
    {
        //using System.Collections;
        public static IEnumerable Power(int number, int exponent)
        {
            int counter = 0;
            int result = 1;
            while (counter++ < exponent)
            {
                result = result * number;
                yield return result;
            }
        }    static void Main()
        {
            // Display powers of 2 up to the exponent 8:
            IEnumerable ie = Power(2, 8);        Console.WriteLine(ie.GetType().ToString());
            foreach (int i in ie)
            {
                Console.Write("{0} ", i);
            }        Console.ReadKey();
        }
    }看到了嘛,这里产生了这个类:
    List+<Power>d__0
      

  14.   

    先转个向,换个思路(foreach的还没有转过弯来,竟然支持分布式运算!!!)
    转向:比较/Comparepublic interface IComparable
    {
        int CompareTo(object obj);
    }public interface IComparer<T>
    {
        int Compare(T x, T y);
    }public interface IComparable<T>
    {
        int CompareTo(T other);
    }public interface IEqualityComparer<T>
    {
        bool Equals(T x, T y);
        int GetHashCode(T obj);
    }using System;
    using System.Collections;
    using System.Runtime.CompilerServices;namespace System.Collections.Generic
    {
        // 摘要:
        //     为 System.Collections.Generic.IComparer<T> 泛型接口的实现提供基类。
        //
        // 类型参数:
        //   T:
        //     要比较的对象的类型。
        [Serializable]
        public abstract class Comparer<T> : IComparer, IComparer<T>
        {
            // 摘要:
            //     初始化 System.Collections.Generic.Comparer<T> 类的新实例。
            protected Comparer();        // 摘要:
            //     返回由泛型参数指定的类型的默认排序顺序比较器。
            //
            // 返回结果:
            //     继承 System.Collections.Generic.Comparer<T> 并作为 T 类型的排序顺序比较器的对象。
            public static Comparer<T> Default { get; }        // 摘要:
            //     在派生类中重写时,对同一类型的两个对象执行比较并返回一个值,指示一个对象是小于、等于还是大于另一个对象。
            //
            // 参数:
            //   x:
            //     要比较的第一个对象。
            //
            //   y:
            //     要比较的第二个对象。
            //
            // 返回结果:
            //     值 条件 小于零 x 小于 y。零 x 等于 y。大于零 x 大于 y。
            //
            // 异常:
            //   System.ArgumentException:
            //     类型 T 没有实现 System.IComparable<T> 泛型接口或 System.IComparable 接口。
            public abstract int Compare(T x, T y);
        }
    }
    using System;
    using System.Globalization;
    using System.Runtime.InteropServices;
    using System.Runtime.Serialization;namespace System.Collections
    {
        // 摘要:
        //     比较两个对象是否相等,其中字符串比较是区分大小写的。
        [Serializable]
        [ComVisible(true)]
        public sealed class Comparer : IComparer, ISerializable
        {
            // 摘要:
            //     表示 System.Collections.Comparer 的实例,它与当前线程的 System.Threading.Thread.CurrentCulture
            //     关联。此字段为只读。
            public static readonly Comparer Default;
            //
            // 摘要:
            //     表示 System.Collections.Comparer 的实例,它与 System.Globalization.CultureInfo.InvariantCulture
            //     关联。此字段为只读。
            public static readonly Comparer DefaultInvariant;        // 摘要:
            //     使用指定的 System.Globalization.CultureInfo 初始化 System.Collections.Comparer 类的新实例。
            //
            // 参数:
            //   culture:
            //     要用于新 System.Collections.Comparer 的 System.Globalization.CultureInfo。
            //
            // 异常:
            //   System.ArgumentNullException:
            //     culture 为 null。
            public Comparer(CultureInfo culture);        // 摘要:
            //     对同一类型的两个对象执行区分大小写的比较,并返回一个值,指示其中一个对象小于、等于还是大于另一个对象。
            //
            // 参数:
            //   a:
            //     要比较的第一个对象。
            //
            //   b:
            //     要比较的第二个对象。
            //
            // 返回结果:
            //     值 条件 小于零 a 小于 b。 零 a 等于 b。 大于零 a 大于 b。
            //
            // 异常:
            //   System.ArgumentException:
            //     a 和 b 都不实现 System.IComparable 接口。- 或 - a 和 b 的类型不同,而且都无法处理与另一个的比较。
            public int Compare(object a, object b);
            //
            // 摘要:
            //     用序列化所需的数据填充 System.Runtime.Serialization.SerializationInfo 对象。
            //
            // 参数:
            //   info:
            //     要用数据填充的 System.Runtime.Serialization.SerializationInfo 对象。
            //
            //   context:
            //     有关序列化的源或目标的上下文信息。
            //
            // 异常:
            //   System.ArgumentNullException:
            //     info 参数为 null。
            public void GetObjectData(SerializationInfo info, StreamingContext context);
        }
    }
      

  15.   

    我是:
    你是:呵呵,真是做梦了~~.NET框架提供了
    [1]IComparable
    [2]IComparable<T>
    [3]IComparer<T>
    [4]IEqualityComparer<T>这几个接口对于实现排序算法有着直接的作用,
    用于编写出通用的排序算法,在处理和集合相关的类型时,
    当你因为具体的语义覆盖了键类型的Equals方法后,
    必须覆盖GetHashCode方法。
    关于这个部分的讨论见我的另一个贴子:
    http://topic.csdn.net/u/20090824/12/67d3acfd-a6e5-4ebe-8261-c16fd28a4d0d.html还剩三个接口,
    IList <T> 
    ICollection <T> 
    IDictionary <TKey,TValue> 
    明天继续得接口者得.net
    整一个面向接口的编程
      

  16.   

    留个链接,自己先看...
    http://www.cnblogs.com/ike_li/articles/1275257.html
      

  17.   

    谢了,ls的两位...http://book.csdn.net/bookfiles/829/index.html
    书名:C#高级编程(第6版)
    第5章 数组
    第10章 集合这本书还真不错,以前没看过....
    这里总结的也真不错.呵呵,还是自己去研究,来得更加"深刻"一点...
    [1]地毯式的,更加全面
    [2]补上linq
    [3]从不了解到了解的过程很清晰...原来接口也支持"协变"
    Ienumerator GetEnumerator()
    IDictionaryEnumerator GetEnumerator()漏了一个ILookup接口,补上...
      

  18.   

    <补上>C#里最难理解的就是语法糖:同样一个yield return
    竟然会有结果完全不同的输出,
    仅仅是受到函数体返回类型的定义.另一段"对比"的代码在47楼using System;
    using System.Collections;
    public class List 

        public static IEnumerator Power(int number, int exponent) 
        { 
            int counter = 0; 
            int result = 1; 
            while (counter++ < exponent) 
            { 
                result = result * number; 
                yield return result; 
            } 
        } 
        
        static void Main() 
        {
            IEnumerator ie = Power(2, 8); 
            Console.WriteLine(ie.GetType().ToString());        //ie.Reset();
            while (ie.MoveNext())
            {
                Console.Write("{0} ", ie.Current);
            }        Console.ReadKey(); 
        } 
    }
      

  19.   


    明白了,Array.Copy(o1,o2,count) 
    另外还有,o1.CopyTo(o2,count)应该把Copy改成CopyTo
    而Copy()方法只是传送了阶数相同、有足够元素空间的已有数组。
    这句是重点,两个数组,阶数要相同,个数可以不同,相容就行.有一个奇怪的地方是:
    Array实现了:IList(包含Insert、Remove、RemoveAt)
    Array没实现:Insert、Remove、RemoveAt
    难道编译器又开小灶了
      

  20.   

    迭代块:包含yield语句的方法或属性
    迭代器接口类型:迭代块必须声明为返回IEnumerator或IEnumerable接口。
    迭代块内容:可以包含多个yield return语句或yield break语句,但不能包含return语句。
    迭代块语法糖:编译器生成一个yield 类型,其中包含一个状态机。语法糖
    #define InCSharp
    //#define Sourceusing System;
    using System.Collections;class MyClass
    {
        static void Main(string[] args)
        {
            IEnumerator enumerator = new HelloCollection().GetEnumerator();
            while (enumerator.MoveNext())
            {
                Console.WriteLine(enumerator.Current);
            }
        }
    }#if Source
    public class HelloCollection//原代码
    {
        public IEnumerator GetEumerator()
        {
            yield return "Hello";
            yield return "World";
        }
    }
    #endifpublic class HelloCollection//转换后代码示意
    {
        public IEnumerator GetEnumerator()
        {
            Enumerator enumerator = new Enumerator();
            return enumerator;
        }    public class Enumerator : IEnumerator, IDisposable
        {
            private int state;
            private object current;        public Enumerator()
            {
                this.current = 0;
            }        public Enumerator(int state)
            {
                this.state = state;
            }        bool System.Collections.IEnumerator.MoveNext()
            {
                switch (state)
                {
                    case 0:
                        current = "Hello";
                        state = 1;
                        return true;
                    case 1:
                        current = "World";
                        state = 2;
                        return true;
                    case 2:
                        break;
                }
                return false;
            }        void System.Collections.IEnumerator.Reset()
            {
                throw new NotSupportedException();
            }        object System.Collections.IEnumerator.Current
            {
                get
                {
                    return current;
                }
            }        void IDisposable.Dispose()
            {
                //to do
            }
        }
    }再来个例子,看看语法糖在哪里
    using System;
    using System.Collections;public class Test
    {
        static void Main(string[] args)
        {
            MusicTitles titles = new MusicTitles();        //foreach默认调用的IEnumerator
            foreach (string title in titles)
            {
                Console.WriteLine(title);
            }
            Console.WriteLine();        //IEnumerable无参数
            Console.WriteLine("reverse");
            foreach (string title in titles.Reverse())
            {
                Console.WriteLine(title);
            }
            Console.WriteLine();        //IEnumerable传入参数
            Console.WriteLine("subset");
            foreach (string title in titles.Subset(2, 2))
            {
                Console.WriteLine(title);
            }
        }
    }public class MusicTitles
    {
        string[] names = { "Tubular Bells", "Hergest Ridge", "Ommadawn", "Platinum" };
        public IEnumerator GetEnumerator()
        {
            for (int i = 0; i < 4; i++)
            {
                yield return names[i];
            }
        }    public IEnumerable Reverse()
        {
            for (int i = 3; i >= 0; i--)
            {
                yield return names[i];
            }
        }    public IEnumerable Subset(int index, int length)
        {
            for (int i = index; i < index + length; i++)
            {
                yield return names[i];
            }
        }
    }
      

  21.   

    GetHashCode也是集合中比较重要的部分,先提一下GetHashCode()方法的实现代码必须满足如下要求:
    ●       相同的对象应总是返回相同的值。
    ●       不同的对象可以返回相同的值。
    ●       应执行得比较快,计算的开销不大。
    ●       不能抛出异常。
    ●       应至少使用一个实例字段。
    ●       散列码值应平均分布在int可以存储的整个数字区域上。
    ●       散列码最好在对象的生存期中不发生变化。集合上的操作主要有以下几种:
    创建
    添加元素
    插入元素
    访问元素
    删除元素
    搜索
    排序
    类型转换杂项有:
    返回只读集合
      

  22.   

    花了整整一天时间,终告一段落...集合位置
    序号 名称 位置 简写
    1 数组类 System System
    2 对象类型集合类 System.Collections Collections
    3 泛型集合类 System.Collections.Generic Generic
    4 特定类型集合类 System.Collections.ObjectModel ObjectModel
    5 集合类基类 System.Collections.Specialized Specialized
    6 Linq类 System.Linq Linq
    相关接口
    序号 位置 名称
    1 System IDisposable
    2 System ICloneable
    3 System IComparable
    4 System IComparable<T>
    5 System IFormattable
    6 System ICustomFormatter
    7 System IFormatProvider
    8 System IEquatable<T>
    10 Collections IEnumerable
    11 Collections ICollection
    12 Collections IList
    13 Collections IDictionary
    14 Collections IEnumerator
    15 Collections IDictionaryEnumerator
    16 Collections IComparer
    17 Collections IEqualityComparer
    18 Collections IHashCodeProvider
    19 Generic IEnumerable<T>
    20 Generic ICollection<T>
    21 Generic IList<T>
    22 Generic IDictionary<TKey,TValue>
    23 Generic IEnumerator<T>
    24 Generic IComparer<T>
    25 Generic IEqualityComparer<T>
    26 Specialized INotifyCollectionChanged
    27 Specialized IOrderedDictionary
    28 Linq IGrouping<TKey,TElement>
    29 Linq ILookup<TKey,TElement>
    30 Linq IOrderedEnumerable<TElement>
    31 Linq IOrderedQueryable
    32 Linq IOrderedQueryable<T>
    33 Linq Iqueryable
    34 Linq IQueryable<T>
    35 Linq IQueryProvider
    所有集合类(注:由于BitVector32未实现枚举接口,不计入)
    序号 名称 虚类 枚举 集合 列表 字典 查询 位置
    1 Array * * * * System
    2 CollectionBase * * * * Collections
    3 KeyedByTypeCollection<TItem> * *T *T *T Generic
    4 KeyedCollection<K,TItem> * *T *T *T ObjectModel
    5 DictionaryBase * * * * Collections
    6 ReadOnlyCollectionBase * * * Collections
    7 NameObjectCollectionBase * * * Specialized
    8 ArrayList * * * Collections
    9 StringCollection * * * Specialized
    10 List<T> *T *T *T Generic
    11 Collection<T> *T *T *T ObjectModel
    12 ObservableCollection<T> *T *T *T ObjectModel
    13 ReadOnlyCollection<T> *T *T *T ObjectModel
    14 SynchronizedCollection<T> *T *T *T Generic
    15 SynchronizedKeyedCollection<K, T> *T *T *T Generic
    16 SynchronizedReadOnlyCollection<T> *T *T *T Generic
    17 Hashtable * * * Collections
    18 SortedList * * * Collections
    19 ListDictionary * * * Specialized
    20 OrderedDictionary * * * Specialized
    21 HybridDictionary * * * Specialized
    22 Dictionary<K,V> *T *T *T Generic
    23 SortedList<K,V> *T *T *T Generic
    24 SortedDictionary<K,V> *T *T *T Generic
    25 Queue * * Collections
    26 Queue<T> *T * Generic
    27 Stack * * Collections
    28 Stack<T> *T * Generic
    29 LinkedList<T> *T *T Generic
    30 BitArray * * Collections
    31 NameValueCollection * * Specialized
    32 NameObjectCollectionBase.KeysCollection * * Specialized
    33 Dictionary<K,V>.KeyCollection *T *T Generic
    34 Dictionary<K,V>.ValueCollection *T *T Generic
    35 SortedDictionary<K,V>.KeyCollection *T *T Generic
    36 SortedDictionary<K,V>.ValueCollection *T *T Generic
    37 HashSet<T> *T T Generic
    38 Lookup<K,TElement> *T T Linq
    39 StringDictionary * Specialized
      

  23.   

    我查过,Array类实现了IList所有的方法,可以用ildasm查看mscorlib.dll,Array实现了System.Collections.IList接口的Add,Clear,Contains,IndexOf,Insert,Remove,RemoveAt,get_Item,set_Item方法
      

  24.   


    多谢rightyeah,现在查清楚了:Insert()/Remove()/RemoveAt()
    对于集合:Insert()方法用于插入元素,Remove()和RemoveAt()可删除元素。
    对于数组:这些方法都抛出NotSupportedException异常。实际上是实现了,但是当作异常来使用。
      

  25.   

    列表类型
    序号 分类 名称 列表 备注
    1 普通列表 Array 列表*[X] 提供创建、操作、搜索和排序数组的方法,因而在公共语言运行库中用作所有数组的基类。
    8 普通列表 ArrayList 列表* 使用大小可按需动态增加的数组实现。
    9 普通列表 StringCollection 列表* 表示字符串集合。
    10 泛型列表 List<T> 列表T 表示可通过索引访问的对象的强类型列表。
    11 泛型列表 Collection<T> 列表T 为泛型集合提供基类。
    12 泛型列表 ObservableCollection<T> 列表T 表示一个动态数据集合,在添加项、移除项或刷新整个列表时,此集合将提供通知。
    13 泛型列表 ReadOnlyCollection<T> 列表T 为泛型只读集合提供基类。
    14 泛型列表 SynchronizedCollection<T> 列表T 提供一个线程安全集合,其中包含泛型参数所指定类型的对象作为元素。
    15 泛型列表 SynchronizedKeyedCollection<K, T> 列表T 提供一个线程安全集合,该集合所含对象的类型由一个泛型参数指定,并且集合根据键进行分组。
    16 泛型列表 SynchronizedReadOnlyCollection<T> 列表T 提供一个线程安全只读集合,该集合包含泛型参数所指定的类型的对象作为元素。
    字典类型
    序号 分类 名称 列表 备注
    17 普通字典 Hashtable 字典* 表示键/值对的集合,这些键/值对根据键的哈希代码进行组织。
    19 普通字典 ListDictionary 字典* 使用单链接列表实现 IDictionary。建议用于通常包含 10 个或 10 个以下项的集合。
    21 普通字典 HybridDictionary 字典* 在集合较小时,使用ListDictionary来实现,当集合变大时,切换到Hashtable。
    18 普通字典 SortedList 字典* 表示键/值对的集合,这些键值对按键排序并可按照键和索引访问。
    20 普通字典 OrderedDictionary 字典* 表示键或索引可访问的键/值对的集合。
    22 泛型字典 Dictionary<K,V> 字典T 表示键和值的集合。
    23 泛型字典 SortedList<K,V> 字典T 表示键/值对的集合,这些键/值对基于关联的IComparer<T>实现按照键进行排序。
    24 泛型字典 SortedDictionary<K,V> 字典T 表示按键排序的键/值对的集合。
    集合类型
    序号 分类 名称 列表 备注
    25 普通集合 Queue 集合* 表示对象的先进先出非泛型集合。
    27 普通集合 Stack 集合* 表示对象的简单的后进先出非泛型集合。
    30 普通集合 BitArray 集合* 管理位值的压缩数组,该值表示为布尔值,其中true表示1,false表示0。
    31 普通集合 NameValueCollection 集合* 表示可通过键或索引访问的关联String键和String值的集合。
    26 泛型集合 Queue<T> 集合t 表示对象的先进先出集合。
    28 泛型集合 Stack<T> 集合t 表示同一任意类型的实例的大小可变的后进先出 (LIFO) 集合。
    29 泛型集合 LinkedList<T> 集合T 表示双向链表。
    特殊类型
    序号 分类 名称 列表 备注
    39 特殊类型 StringDictionary 枚举* 将键和值强类型化为字符串而不是对象来实现哈希表。
    38 特殊类型 Lookup<K,E> 查询t 表示映射到一个或多个值的各个键的集合。
    37 特殊类型 HashSet<T> 查合t 表示值的集。
    辅助类型
    序号 分类 名称 列表 备注
    32 辅助集合 NameObjectCollectionBase.KeysCollection 集合* 表示集合的String键的集合。
    33 辅助集合 Dictionary<K,V>.KeyCollection 集合T 表示Dictionary<K,V>中键的集合。无法继承此类。
    34 辅助集合 Dictionary<K,V>.ValueCollection 集合T 枚举Dictionary<K,V>.ValueCollection的元素。
    35 辅助集合 SortedDictionary<K,V>.KeyCollection 集合T 枚举SortedDictionary<K,V>的元素。
    36 辅助集合 SortedDictionary<K,V>.ValueCollection 集合T 枚举SortedDictionary<K,V>.ValueCollection的元素。
    2 辅助基类 CollectionBase 列表*[X] 为强类型集合提供 abstract 基类。
    3 辅助基类 KeyedByTypeCollection<I> 列表T[X] 提供一个集合,该集合的项是用作键的类型。
    4 辅助基类 KeyedCollection<K,I> 列表T[X] 提供集合键嵌入在值中的集合的抽象基类。
    5 辅助基类 DictionaryBase 字典*[X] 为键/值对的强类型集合提供 abstract 基类。
    6 辅助基类 ReadOnlyCollectionBase 集合*[X] 为强类型非泛型只读集合提供 abstract 基类。
    7 辅助基类 NameObjectCollectionBase 集合*[X] 为关联的String键和Object值的集合(可通过键或索引来访问它)提供abstract基类。
      

  26.   

    =================
    先对上贴作个说明:
    =================
    *代表仅非泛型接口的实现
    T代表非泛型和泛型接口同时实现
    t代表仅泛型接口的时实现
    [x]代表abstract类型========
    关系图谱
    ========
    IList        --
                    +-->ICollection  -->Ienumerable
    IDictionary  --       /\
                                           |
    Ilist<>      --                        |     
                    +-->Icollection<>-->Ienumerable<>
    Idictionary<>--    ILookup<>
            
    ========
    进化过程
    ========           
    枚举-->集合-->(列表/字典)*有兴趣的可以看一下《C#核心技术》这本书书,算是介绍的比较详细了。发现网上关于集合问的比较多,但是没有答清楚的一个问题:
    是List<T>与Collection<T>的区别是什么?
    Collection<T>实现了List<T>的功能,
    区别在于Collection可以当作基类,重载以下四个方法和一个属性,
    以便对元素进行控制,而List只能进行枚举。
    System.Collections.ObjectModel.Collection<T>.ClearItems()
    System.Collections.ObjectModel.Collection<T>.InsertItem(int, T)
    System.Collections.ObjectModel.Collection<T>.RemoveItem(int)
    System.Collections.ObjectModel.Collection<T>.SetItem(int, T)
    System.Collections.ObjectModel.Collection<T>.Items
      

  27.   

    集合:面向接口编程的最好示范,
    这个先放一放,从今天开始学习Lamada,先从Lamada糖糖开始...
    总算搞清楚,原来lamada返回的是一个怪胎:
    System.Linq.Enumerable+<SelectIterator>d__d`2[System.String,System.String]using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;class Test
    {
        public static void Main(string[] args)
        {
            string[] ss = { "a", "a", "a", "a", "a", };
            IEnumerable ie = ss.Select(s => s);
            Console.WriteLine(ie.GetType());        Console.ReadKey();
        }
    }
    class _SelectIterator_d__d<TSource, TResult> : IEnumerable<TResult>, IEnumerable, IEnumerator<TResult>, IEnumerator, IDisposable
    {
        // Fields
        private int __1__state;
        private TResult __2__current;
        public Func<TSource, TResult> __3__selector;
        public IEnumerable<TSource> __3__source;
        public IEnumerator<TSource> __7__wrapf;
        private int __l__initialThreadId;
        public TSource _element_5__e;
        public Func<TSource, TResult> selector;
        public IEnumerable<TSource> source;    // Methods
        public _SelectIterator_d__d(int __1__state)
        {
            //to do
        }    private void __m__Finally10() 
        {
            //to do 
        }    public bool MoveNext() 
        { 
            return default(bool); 
        }    IEnumerator<TResult> IEnumerable<TResult>.GetEnumerator() 
        { 
            return default(IEnumerator<TResult>); 
        }    IEnumerator IEnumerable.GetEnumerator() 
        { 
            return default(IEnumerator); 
        }
        
        void IEnumerator.Reset() 
        {
            //to do
        }
        void IDisposable.Dispose() 
        {
            //to do
        }    // Properties
        TResult IEnumerator<TResult>.Current 
        { 
            get 
            { 
                return default(TResult); 
            } 
        }    object IEnumerator.Current 
        { 
            get 
            { 
                return default(object); 
            } 
        }
    }
      

  28.   

    多谢aloneone上面的代码还有错,需要进一步的改进.
    [1]返回的对象,改为内置类,并限内部访问
    private sealed class _SelectIterator_d__d<TSource, TResult>
    [2]代码的枚举没去看...lamada表达式,从本质上讲,无非是C#一些特性的组合,再加一点编译器的小魔法:
    [1]扩展方法
    这次让我看到了扩展方法不一样的地方,
    让我没有想到的是,他不但作用在对象上,更重要的是能够在接口上也进行扩展
    A:在这里,扩展方法是实施在IEnumerable接口上的(实际上还没有具体的类型存在)
    B:扩展方法把调用的对象从参数中提取出来的,这个好象比A更重要,A还有可以通过别的途来实现
    否则我们将写成:Enumerable.Select(i_s, s => s + 1);
    实现前:IEnumerable ie = Enumerable.Select(i_s, s => s + 1);
    实现后:IEnumerable ie = i_s.Select(s => s + 1);
    [2]类型推导
    废话不多说了,没有类型推导,我们将写成如下的样子
    实现前:IEnumerable ie = i_s.Select<int,int>(s => s + 1);
    实现后:IEnumerable ie = i_s.Select(s => s + 1);
    类型推导还有一个副产品,就是VAR.
    [3]闭包
    这个才是关键中的关键,不想多说了,具体见我的另一个贴子:
    http://topic.csdn.net/u/20090821/13/7c30e8cb-3d37-4d4f-9c11-0df1dd7be8f4.html
    因为java没能实现闭包,而C#在2.0时实现的,所以说java永远实施不了LINQ
    简单点说,如果没有闭包,将不会有lamada表达式的传递性写法.
    [4]匿名方法
    需要使用委托delegate,并传入方法
    实现前:ie = i_s.Select(new Func<int,int>(delegate(int i){return i+1;}));
    实现后:IEnumerable ie = i_s.Select(s => s + 1);
    [5]泛型
    这个就不多说了
    [6]编译器魔法
    A:编译器自动生成的_SelectIterator_d__d<TSource, TResult>对象
    B:C#3.0中的简写:s=>s+1,得益于类型识别,省了(),return {},看上去清爽多了
    [7]其它
    其它应该没有了吧,
    有的话请你补充.
    总结一下:
    [1]一定是基于集合类型的操作,实现了:IEnumerable 
    [2]表达式被编译器转换成委托和静态扩展方法。
    [3]执行扩展方法的返回一个实现了IEnumerable<T> 接口的"编译器自动生成类型"对象。
    [4]这个"对象"传递了"数据源",以及委托方法的引用。
    [5]一切尽在代码中....
      

  29.   

    多谢jack_ailly
    呵呵,又能三贴子...第一时间,边写边想有点乱,对上一回复做一点更正.
    A:匿名方法
    需要使用委托delegate,并传入方法
    实现前:ie = i_s.Select(new Func <int,int>(delegate(int i){return i+1;}));
    实现后:IEnumerable ie = i_s.Select(s => s + 1); 
    //这个实际还是匿名方法,不过想信大家都能看明白,别外写一个方法,再传入方法明.
    这里做一点小的展开,这个实际上是C#2.0的一个新特征,一般书上没写,大家也未必在意,
    正式的名称应该叫做:方法组转换
    B:我指的没时间IL了
    代码实际上还是来自于IL的,不过用的别人代码残片,
    代码是不完整的,编译也是通不过的,没有上下文案例了,
    补全了,但_SelectIterator_d__d还没有完整地实现(实在不想IL,也从没用过)
    不过这些都不重要,并不妨碍我理解集合.
    要注意,虽然我在讲lamada,但我的注意力:
    一样是放在集合上的,跟IEnumerable有关的一切...
      

  30.   

    顶[align=center]
    ****************************************************************
                看帖一定要回,分也一定要接哦 ^_^
    ****************************************************************[/align]
      

  31.   

    先记一下,以后有用.
    IEnumerable 的泛型版和非泛型版using System;
    using System.Collections;
    using System.Collections.Generic;public class GenericList<T> : System.Collections.Generic.IEnumerable<T>
    {
        protected Node head;
        protected Node current = null;    // Nested class is also generic on T
        protected class Node
        {
            public Node next;
            private T data;  //T as private member datatype        public Node(T t)  //T used in non-generic constructor
            {
                next = null;
                data = t;
            }        public Node Next
            {
                get { return next; }
                set { next = value; }
            }        public T Data  //T as return type of property
            {
                get { return data; }
                set { data = value; }
            }
        }    public GenericList()  //constructor
        {
            head = null;
        }    public void AddHead(T t)  //T as method parameter type
        {
            Node n = new Node(t);
            n.Next = head;
            head = n;
        }    public void Add(T t)
        {
            AddHead(t);
        }    // Implementation of the iterator
        public System.Collections.Generic.IEnumerator<T> GetEnumerator()
        {
            Node current = head;
            while (current != null)
            {
                yield return current.Data;
                current = current.Next;
            }
        }    // IEnumerable<T> inherits from IEnumerable, therefore this class 
        // must implement both the generic and non-generic versions of 
        // GetEnumerator. In most cases, the non-generic method can 
        // simply call the generic method.
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            //return GetEnumerator();
            Node current = head;
            while (current != null)
            {
                yield return current.Data;
                yield return current.Data;
                current = current.Next;
            }
        }
    }class MyClass
    {
        static void Main(string[] args)
        {
            GenericList<int> list = new GenericList<int> { 1, 2, };        IEnumerable<int> ieT = list;
            long beginT = System.DateTime.Now.Ticks;
            foreach (var jT in ieT)
            {
                Console.WriteLine(jT);
            }
            long endT = System.DateTime.Now.Ticks;
            Console.WriteLine("需要" + System.TimeSpan.FromTicks(endT - beginT).Milliseconds + "毫秒");        IEnumerable ie = list;
            long begin = System.DateTime.Now.Ticks; 
            foreach (var j in ie)
            {       
                Console.WriteLine(j);
            }
            long end = System.DateTime.Now.Ticks;
            Console.WriteLine("需要" + System.TimeSpan.FromTicks(end - begin).Milliseconds + "毫秒");        Console.ReadKey();
        }
    }
      

  32.   

    关于类型推导不是LAMADA的专利品:class MyClass
    {
        static void Swap<T>(ref T lhs, ref T rhs)
        {
            T temp;
            temp = lhs;
            lhs = rhs;
            rhs = temp;
        }    static void Main(string[] args)
        {
            int a = 1;
            int b = 2;        Swap<int>(ref a, ref b);
            Swap(ref a, ref b);//类型识别也可以这样用
            //只是规则还没有总结好
            //比如NEW的情况下就不行
            System.Console.WriteLine(a + " " + b);
        }
    }