Operator Overloading For Builtin Types

后端 未结 4 1620
渐次进展
渐次进展 2020-12-21 15:35

How can I override operators to be used on builtin types like String, arrays etc? For example: I wish to override the meaining of the + operator for arrays.

4条回答
  •  没有蜡笔的小新
    2020-12-21 16:28

    Basically you can't.

    You can use extension methods to add functionality like this:

    public void CustomAdd( this Array input, Array addTo ) {
        ...
    }
    

    But this doesn't work with operators.

提交回复
热议问题