c# 到 vb.net 的转换 - Action(Of T, string) 作为元组项

标签 c# vb.net

我正在尝试将元组从 c# 转换为 vb.net。这是元组的声明 -

private List<Tuple<string, string, Action<T, string>>> items = new List<Tuple<string, string, Action<T, string>>>();

然后我像这样将项目添加到 Item3(操作)-

foreach(var iforeach(var i in items)
{
    i.Item3(t, string.Empty);
}

在 vb.net 中,我将我的元组定义如下 -

Private list As New List(Of Tuple(Of String, String, Action(Of T, String)))

并尝试像这样向 Item3 添加一个 Action -

Dim mytype = Activator.CreateInstance(Of T)
For Each item As Tuple(Of String, String, Action(Of T, String)) In list
    item.Item3(mytype, String.Empty)
Next

我已经尝试了各种不同方法的迭代来向 Item3 添加 Action,但似乎没有用。 对于上面的示例,我在 VS 中收到以下消息 - 引用 .... 的参数数量不正确。

谁能阐明如何将其转换为 vb.net?谢谢。

最佳答案

您不需要使用单独的变量 - 只需使用显式的空括号对来防止编译器混淆(将“Item3”误解为参数化属性,如 Darryl 所述):

For Each i In items
    i.Item3()(mytype, String.Empty)
Next i

关于c# 到 vb.net 的转换 - Action(Of T, string) 作为元组项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34050025/

相关文章:

c# - 使用 DateTime.ParseExact 时,如何指定给定日期的时区?

c# - UWP 捕获 ListView 滚动事件

c# - LINQ to Entities 区分大小写比较

vb.net - 我做错了什么: Structure cannot be indexed because it has no default property (WITH CLAUSE)

vb.net - 将常量数组传递给 VB.NET 中的函数

c# - Selenium 驱动程序服务未启动

c# - 使用流编写器集成测试功能

vb.net - 我如何处理在 New 中引发的事件?

c# - 与 Fileupload 控件的最大文件大小相关的问题

vb.net - 如何编写 Visual Basic for 循环步长增量代码?