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

标签 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

最佳答案

这是转换器中的错误。

Key prefix用于匿名类型以影响平等;类型化对象初始值设定项是非法的。

删除它。

关于c# - 从 C# 转换为 VB.NET 后 Key 属性出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46270872/

相关文章:

C# 为 MarshalAs 属性类定义自定义 UnmanagedType

vb.net - vba 语言中的变量作用域类型

vb.net - 需要将 C# 转换为 VB.NET

c# - 我如何将此 C# 属性转换为 VB

c# - 如何在 WPF 中使用多个 ViewModel 并通过一个 MainViewModel 绑定(bind)它们?

c# - 在 XML 文档中使用 <see cref =""/> 和可选的可为空参数

c# - 为什么随机数和正确猜测之间有很强的相关性?

database - “列 'CustID' 不允许为空。”尝试写入 Access 数据库 VB.net 时出错

Mysql查询多个有关系的表中的2个日期

c# - C# -> VB 转换后 `New SomeClass { Key .SomeProperty = SomeValue }` 中的语法错误