Some times while coding, We need to check for null string other wise it will throw an exception.
suppose we are using tostring() method on a string, it will throw a exception while using with null string.
To avoid exception either we can use Convert.ToString(input_string) or just replace the input_string null value with empty string.
So using Convert.ToString method is solution for one case only, So we can go with other solution to replace the null string with empty one. It will avoid unwanted exception. This code will help you to convert the null string to empty string.
/// <summary>
/// Returns a converted null to an empty string.
/// </summary>
public static string ConvertNullToEmptyString(string strinput)
{
return (strinput == null ? "" : strinput);
}
String.IsNullOrEmpty?
ReplyDelete