Overloading function call operator in C#

前端 未结 7 497
北荒
北荒 2020-12-01 13:56

Is it possible to overload the default function operator (the () operator) in C#? If so - how? If not, is there a workaround to create a similar affect?

Thanks,

7条回答
  •  执念已碎
    2020-12-01 14:36

    There is not. Section 7.2.2 of the C# specification defines the overloadable operators as:

    UNARY: + - ! ~ ++ -- true false
    BINARY: + - * / % & | ^ << >> == != > < >= <=

    Your readability would go to all hell anyway. Maybe there's another way to achieve what you're trying to do?

提交回复
热议问题