How not to Code: The String Identity Function

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:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s