我正在尝试将元组从 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/