Click here to Skip to main content
15,665,276 members
Articles / Programming Languages / C#
Posted 30 May 2011

Tagged as


2 bookmarked

Handy Extension Methods

Rate me:
Please Sign up or sign in to vote.
2.83/5 (3 votes)
30 May 2011CPOL
Here are a couple of my favorite extension methhods. What are yours?
using System.Collections.Generic;
using System.Text.RegularExpressions;

public static class ExtensionMethods
    /// <summary>
    /// Add a sequence to a collection.
    /// </summary>
    /// <typeparam name="T">Object type.</typeparam>
    /// <param name="coll">Generic collection.</param>
    /// <param name="seq">Generic sequence.</param>
    public static void Add<T>(this ICollection<T> coll, IEnumerable<T> seq)
        foreach (T item in seq)

    /// <summary>
    /// Indicates whether the specified string is null, empty, or whitespace.
    /// </summary>
    /// <param name="value">The string to test.</param>
    /// <returns>Value indicating whether string contains squat.</returns>
    public static bool IsNullEmptyOrWhitespace(this string value)
        return string.IsNullOrEmpty(value) || !Regex.IsMatch(value, @"\S");


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

Written By
Software Developer Insight Global
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

GeneralYou don't need to use regular expressions to test for white-... Pin
Richard Deeming8-Jun-11 6:23
mveRichard Deeming8-Jun-11 6:23 
GeneralReason for my vote of 3 Nice idea but already done by C#. My... Pin
Ed Nutting5-Jun-11 23:38
Ed Nutting5-Jun-11 23:38 
Reason for my vote of 3
Nice idea but already done by C#. My 3
GeneralShould be noted these functions already exist - System.Colle... Pin
Ed Nutting5-Jun-11 23:37
Ed Nutting5-Jun-11 23:37 
GeneralWhy not combine string.IsNullOrWhiteSpace instead of using r... Pin
Mycroft Holmes30-May-11 15:17
professionalMycroft Holmes30-May-11 15:17 

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.