Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Handy Extension Methods

By , 2 Jun 2011
Rate this:
Please Sign up or sign in to vote.

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;


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

About the Author

Software Developer 5TH Cell
United States United States
Tools & gameplay programmer at 5TH Cell Media.
DigiPen student class of '09.

Comments and Discussions

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

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 2 Jun 2011
Article Copyright 2011 by IGood
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid