I read this MSDN document regarding the operator overloading.
In that example, the operators used were +, - and also can define others * or /.
I want to overload ?? operator to be used for strings like
string emptyString = emptyString ?? "OtherValue";
instead of
string emptyString = string.IsNullOrEmpty(emptyString) ? "OtherValue" : emptyString;
I don’t want to convert string to object and compare using ??.
I know that ?? is used for nullable value types, what MSDN says:
The ?? operator is called the null-coalescing operator and is used to define a default value for nullable value types or reference types.
It returns the left-hand operand if the operand is not null; otherwise it returns the right operand.
I want to ask you if is possible to overload this operator in C#. The above example is a simple situation when need to use ??.
No. Please take a look here Overloadable Operators C# . Section ‘These operators cannot be overloaded.’