【问题标题】:Operator = is not defined for types UIElement and UIElement ..?运算符 = 没有为 UIElement 和 UIElement 类型定义 ..?
【发布时间】:2012-03-07 09:31:09
【问题描述】:

我将一些代码从 C# 翻译成 VB.NET,(WPF,.NET 4)

C#

// Update the Z-Index of every UIElement in the Canvas.
foreach( UIElement childElement in base.Children )
{
    if( childElement == element )
        Canvas.SetZIndex( element, elementNewZIndex );

VB.NET(自动翻译)

' Update the Z-Index of every UIElement in the Canvas. '
For Each childElement As UIElement In MyBase.Children
  If childElement = element Then        ' <<<<<<<<<<<<< Compile ERROR '
    Canvas.SetZIndex(element, elementNewZIndex)

编译错误:

错误 4 未为类型定义运算符“=” 'System.Windows.UIElement' 和 'System.Windows.UIElement'。

怎么可能,在 C# 中定义了运算符,但在 VB.NET - NOT(?)

【问题讨论】:

    标签: c# wpf vb.net c#-to-vb.net uielement


    【解决方案1】:

    尝试改用childElement.Equals(element)

    【讨论】:

    • 如何在 C# 中定义运算符,但在 VB 中 - 不是..?
    • 阅读本文 (codeproject.com/Articles/18714/…);文末讨论vb.net中的平等
    • 我认为这实际上并不能回答 OP 的问题。我认为 OP 想知道 为什么 = 运算符在 VB.Net 中不起作用,而不是如何修复代码。文章说“VB.NET 没有 == 运算符,或任何与其等效的运算符。”没有任何解释,这至少是不完整的,因为有 = 运算符可以重载。
    • 我同意 ken2k... 顺便说一句,还有一个选项childElement Is element...?
    猜你喜欢
    • 2013-10-25
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多