Possible to overload null-coalescing operator?

后端 未结 6 1952
栀梦
栀梦 2020-12-17 07:54

Is it possible to overload the null-coalescing operator for a class in C#?

Say for example I want to return a default value if an instance is null and return the i

6条回答
  •  难免孤独
    2020-12-17 08:10

    According to the ECMA-334 standard, it is not possible to overload the ?? operator.

    Similarly, you cannot overload the following operators:

    • =
    • &&
    • ||
    • ?:
    • ?.
    • checked
    • unchecked
    • new
    • typeof
    • as
    • is

提交回复
热议问题