How do I check if a string is null and set it to some value if it is?
Like in SQL,
isnull(string, 0)
You could test for null:
if (s == null)
s = "Hello";
or use the null coalescing operator:
string null_s = null;
string non_null_s = null_s ?? "Hello";
If you want to catch empty strings too, then you could use the IsNullOrEmpty test:
if (String.IsNullOrEmpty(s))
s = "Hello";
string.IsNullOrEmpty() would mean you can't use ??, only the if statement (or if-else).