Overloading the + operator to add two arrays

后端 未结 5 1740
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 18:53

What\'s wrong with this C# code? I tried to overload the + operator to add two arrays, but got an error message as follows:

One of the parameters of a binary operato

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 19:32

    When you want to overload le + operator between type AA and BB, you must do it in the class AA or BB and not in a class named Program (like you did).

    Unfortunatly, you cannot write code in the Array class.

    What you can do is to

    • create your own class that implements IList
    • and put the + operator on that class.

    If you need more detailed implementation, just ask me.

提交回复
热议问题