Monday, January 30, 2012

Best Extension Methods: Is Matching with one of any String

Using below extension method we can check that a value is matching with one of any parameter or not...

    //  below function is replacement for such condition   if(reallyLongStringVariableName == "string1" || 
    //    reallyLongStringVariableName == "string2" || 
    //    reallyLongStringVariableName == "string3")
    //  // do something....
    public static bool In(this T source, params T[] list)
        if (null == source) throw new ArgumentNullException("source");
        return list.Contains(source);

Compiled By: Rajesh Rolen

Share This!

No comments:

Powered By Blogger · Designed By Seo Blogger Templates