IfNullElse

 /// <summary>
        /// Check if string is null or white spaces and return a value
        /// </summary>
        /// <param name="input">string to check</param>
        /// <param name="nullAlternateValue">value to be returned in case string is null</param>
        /// <returns>string: original or null alternative value</returns>
        public static string IfNullElse(this string input, string nullAlternateValue)
        {
            return  (!string.IsNullOrWhiteSpace(input)) ? input : nullAlternateValue;
        }
Example:
 string s = "test";
            MessageBox.Show(s.IfNullElse("Null Alternate Value"));
            s = "";
            MessageBox.Show(s.IfNullElse("Null Alternate Value"));

Description

Check if string is null or white spaces and return null alternate value

Details

Double click on the code to select all.

 

;