Ok, so I am new to C Sharp and I have one function call which might send null values. I want to make sure that if its null then I should set those null as empty string. Below is what I have tried and it works but I think there must be an elegant way to achieve this.
public static Concat ()
{
// imagine x = null and y = null
Abc( x, y);
}
public static Abc ( string x , string y)
{
// blah blah
x = x ?? "";
y = y ?? "";
efg( x, y);
}
I looked into this Solution but I could not understand it. Can I do something in the Abc arguments/parameter itself. I mean
public static Abc ( string x Can I do something here , string y Can I do something here)
{
// blah blah
x = x ?? "";
y = y ?? "";
efg( x, y);
}
string(andnullis a valid value for a string), then null can be passed as the parameter value. Your example snippet will do the trick though:x = x ?? "";can be read as "set x = x if x is not null, but if it's null, set it to blank string.public static Abc(string! x, string! y)where the exclamation marks would mean that the compiler guarantees these are never null. For some related suggestions for future C# features, see for example Proposal: Nullable reference types and nullability checking.