我已经设置了一个字典和元组,如下所示:
var myDict = new Dictionary<string, Tuple<string, string>>();
private void SetValue()
{
var myTuple1= Tuple.Create("ABC", "123");
var myTuple2= Tuple.Create("DEF", "456");
myDict.Add("One", myTuple1)
myDict.Add("Two", myTuple2)
}
我正在尝试检索GetValue()中的元组,如下所示:
private void GetValue()
{
var myTuple = new Tuple<string, string>("",""); //Is this correct way to initialize tuple
if (myDict.TryGetValue(sdsId, out myTuple))
{
var x = myTuple.Item1;
var y = myTuple.Item2;
}
}
我的问题是在从字典中检索元组时,这是否是正确的初始化元组的方式?是否有更好的代码?
var myTuple = new Tuple<string, string>("","");