ExtensionMethod.NET Home of 840 C#, Visual Basic, F# and Javascript extension methods

Uppercase with null check

Converts a string to upper-case but checks for null strings first


public static String ToUpperCheckForNull(this string input)

    string retval = input;

    if (!String.IsNullOrEmpty(retval))
        retval = retval.ToUpper();

    return retval;



string g = "potatoe";

return g.ToUpperCheckForNull();

will return "POTATOE"

Author: Russell Holmes

Submitted on: 17 dec 2014

Language: C#

Type: string

Views: 3295