Yes, you are right - they are not the same, and as you indicated.
If you are not comfortable with the first form, you can write the extension:
public static string DefaultIfNullOrEmpty(this string x, string defaultValue) { return string.IsNullOrEmpty(x) ? defaultValue : x; }
then you can simply write:
s.DefaultIfNullOrEmpty("default")
in your main code.
source share