我正在将此 VB.NET 代码转换为 C#。
Dim dict As New Dictionary(Of String, String)
If dict.TryGetValue(key, val) Then
dict.Item(key) = val & "~" & row.Item(y).ToString
Else
dict.Add(key, row.Item(y).ToString)
End If
这是 C# 代码。注意 If dict.TryGetValue 之后的行。 Intellisense 不显示 C# 中的 Item 属性。 C# 的正确语法是什么?
Dictionary<string, string> dict = new Dictionary<string, string>();
if (dict.TryGetValue(key, out val)) {
dict.Item[key] = val + "~" + row.ItemArray[y].ToString();
} else {
dict.Add(key, row.ItemArray[y].ToString());
}
最佳答案
在 C# 中访问字典中键的值的方式如下:
dict[key]
话虽这么说:
dict.Item[key] = val + "~" + row.ItemArray[y].ToString();
应该改变如下:
dict[key] = val + "~" + row.ItemArray[y].ToString();
关于c# - C# 中缺少 Dictionary(of String, String) Item 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42653533/