C# 中的扩展方法

1.是否有子元素

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

2.IsBetween

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

3.each

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

你可能感兴趣的:(C#)