Click here to Skip to main content
15,868,141 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Handy Extension Methods

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
2 Jun 2011CPOL 6.5K   1
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.)


C#
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;
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Undead Labs
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralClamp is cool... Here is the generics alternate: pub... Pin
Aiscrim8-Jun-11 0:51
Aiscrim8-Jun-11 0:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.