• IEnumerable接口的扩展方法


    /// <summary>
    /// IEnumerable接口的扩展方法,支持它的实现类是List的情况
    /// </summary>
    using System.Collections.Generic;
    public static class IEnumerableExtensions
    {
    /// <summary>
    /// 向集合中添加元素
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="collection"></param>
    /// <param name="value"></param>
    public static void Add<T>(this IEnumerable<T> collection, T value)
    {
    (collection as List<T>).Add(value);
    }
    /// <summary>
    /// 从集合中删除元素
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="collection"></param>
    /// <param name="value"></param>
    public static void Remove<T>(this IEnumerable<T> collection, T value)
    {
    (collection as List<T>).Remove(value);
    }
    /// <summary>
    /// 检索集合中是否包含某个元素
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="collection"></param>
    /// <param name="value"></param>
    /// <returns></returns>
    public static bool Contains<T>(this IEnumerable<T> collection, T value)
    {
    return (collection as List<T>).Contains(value);
    }
    }

  • 相关阅读:
    jQuery中的DOM操作
    jQuery选择器
    面试问题总结
    oracle日期操作
    Oracle报错:ORA-02064: distributed operation not supported
    JDK源码-String
    JDK源码-HashSet
    JDK源码-TreeMap
    JDK源码-Vector
    AJAX验证用户是否存在
  • 原文地址:https://www.cnblogs.com/niuzaihenmang/p/5608098.html
Copyright © 2020-2023  润新知