C#:二元运算符重载:不包含类型?
无论如何,是否可以在没有包含类型或使用扩展方法的情况下重载二元运算符?
我想重写两个字节数组之间的 ==
运算符,并且希望不需要扩展方法。
非常感谢任何帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是完全不可能的;扩展运算符不存在。
This is completely impossible; extension operators do not exist.
这不仅不可能,而且听起来非常危险。这正是他们与 C++ 不同的限制运算符重载的原因。它们为您提供了运算符允许的许多表达能力,但避免了 C++ 提供的许多陷阱。
这样做并给其他开发人员带来意想不到的结果的人数可能会很可怕。
创建一个方法。
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.