简体   繁体   中英

C#: Binary Operator Overloading : Without containing type?

Is there anyway to overload a binary operator without have the containing type or using an extension method?

I want to override the == operator between two byte arrays, and hopefully, without an extension method.

Any help is greatly appreciated.

This is completely impossible; extension operators do not exist.

Not only is it impossible, but it sounds downright dangerous. This is exactly why they limited operator overloading unlike C++. They give you a lot of the expressiveness that operators allow, but avoid many of the pitfalls that C++ provided.

The number of people that would do this and cause unexpected results for their fellow developers would probably be scary.

Create a method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM