C# 中的扩展方法

来源:互联网 发布:macbook如何删除软件 编辑:程序博客网 时间:2024/05/17 09:44

1.是否有子元素

public static bool HasElements(this ICollection items){    return items != null && items.Count > 0;}

2.IsBetween

public static bool IsBetween<T>(this T value, T low, T high) where T : IComparable<T>{    return value.CompareTo(low) >= 0 && value.CompareTo(high) <= 0;}

3.each

public static void Each<T>(this ICollection<T> items, Action<T> action){    foreach (T item in items)    {        action(item);    }}

0 0
原创粉丝点击