65.9K
CodeProject is changing. Read more.
Home

Handy Extension Methods

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Jun 2, 2011

CPOL
viewsIcon

6924

I'm a fan of these guys... (Though I feel like I might catch some flack for the first one.)public static bool IsNullOrEmpty(this ICollection collection){ return collection == null || collection.Count == 0;}public static float Clamp(this float value, float low, float hi){...

I'm a fan of these guys... (Though I feel like I might catch some flack for the first one.)

public static bool IsNullOrEmpty<T>(this ICollection<T> collection)
{
    return collection == null || collection.Count == 0;
}

public static float Clamp(this float value, float low, float hi)
{
    System.Diagnostics.Debug.Assert(low < hi);
    value = (value < low) ? low : value;
    return (value > hi) ? hi : value;
}