How not to Code: The String Identity Function

9 12 2008

Yesterday I started working on a small system that’s been having some problems lately. Reviewing the code, I quickly came across the following function:

public static string IsNullToString(string _str)
{
    string name = null;
    if (_str != null)
    {
        name = _str.ToString();
    }
    return name;
}

Now, it seems that if that function receives a null it returns a null, and for other string it’s returning that string. Remembering that String is a sealed class and cannot be inherited, and that String.ToString() does very little, I fail to see why this function is used every time a string is printed out, 108 times in the code…

See Also:


Actions

Information

Leave a comment