从C#转换为VB.NET后,Key属性出错

时间:2017-09-18 02:43:31

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

我已通过http://converter.telerik.com/

将以下C#代码转换为VB.NET代码
public static MessageBoxResult Show(string caption, string text, MessageBoxButton button, MessageBoxImage image)
{
    _messageBox = new WpfMessageBox { Label1 = { Content = caption }, Label2 = { Content = text } };
    return _result;
}

这是转换后的VB.NET代码。

Public Shared Function Show(caption As String, text As String, button As MessageBoxButton, image As MessageBoxImage) As MessageBoxResult
    _messageBox = New WpfMessageBox() With { _
        Key .Label1 = {Key .Content = caption}, _
        Key .Label2 = {Key .Content = text} _
    }
    Return _result
End Function

这是错误:

Error

2 个答案:

答案 0 :(得分:2)

这是转换器中的错误。

Key prefix用于匿名类型以影响相等性;对于类型化对象初始化器,它是不合法的。

删除它。

答案 1 :(得分:1)

转换器似乎认为这里涉及匿名类型,但没有。删除Key

Public Shared Function Show(caption As String, text As String, button As MessageBoxButton, image As MessageBoxImage) As MessageBoxResult
    _messageBox = New WpfMessageBox()
    _messageBox.Label1.Content = caption
    _messageBox.Label2.Content = text
    Return _result
End Function