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

Uppercase with null check

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

Source

public static String ToUpperCheckForNull(this string input)
{

    string retval = input;

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

    return retval;

}

Example

string g = "potatoe";

return g.ToUpperCheckForNull();

will return "POTATOE"

Author: Russell Holmes

Submitted on: 17 dec 2014

Language: C#

Type: string

Views: 7178