重载“And”的示例是什么? VB.NET 中的运算符?
因此,对于查找“And”或“Or”等重载运算符的示例,Google 并不是一个好的选择,因为它会尝试将它们解析为搜索查询本身的运算符。 MSDN 也没有提供如何实现重载 And 运算符的示例,因此我不确定如何为我的项目正确重载它。
有人至少有一个“和”的例子吗? “或”或“异或”(或任何其他)将是一个奖励。我不确定是否需要在我的对象中重载这些运算符,因为我仍在构建它们并且还没有计划。但是,拥有可能被谷歌索引的例子可能会帮助很多人保持理智......
So Google's not a good choice for looking up examples for overloaded operators like "And" or "Or", because it tries to parse them as operators to the search query itself. MSDN also provides no examples of how to implement an overloaded And operator, so I'm not certain how to properly overload it for my project.
Does anyone have an example of "And" at minimum? "Or" or "Xor" (or any others) would be a bonus. I'm not certain if I need to overload these operators in my objects just yet, as I'm still building them out and haven't planned beyond just yet. But having examples around that might get indexed by Google will probably help save the sanity of a lot of people...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以与重载一元或算术运算符相同的方式重载逻辑运算符。
我实际上无法想到目前这会很有用的情况,但为了举例,下面是一个覆盖
And
和Or
运算符的示例结构:此 MSDN 页面 给出了一些其他示例和进一步的解释。
You overload the logical operators in the same way that you overload the unary or arithmetic operators.
I can't actually think of a case where this would be useful at the moment, but for the sake of example, here's a sample structure that overrides the
And
andOr
operators:This MSDN page gives some other examples and further explanation.
这里是 MSDN 上的一篇文章,解释运算符重载在 VB.NET 2005 中,这应该仍然与 2010 相关。
文章中的
Add
示例(使用文章中定义的ComplexNumber
类):Here is an article on MSDN explaining operator overloading in VB.NET 2005, this should still be relevant to 2010.
The example for
Add
, from the article (using theComplexNumber
class defined in the article):