我对C#很陌生,所以请相应指示。我有这个声明:
Dictionary<string, Tuple<string, string>> myDictionary = new Dictionary<string, Tuple<string, string>>();
我想将元组的键和字段设置为:
myDictionary.Add( myKey, Tuple<firstValue, secondValue> );
其中firstValue和secondValue是将成为另一个字典的键的字符串。我想在.Add()方法中初始化元组的语法方面提供一些帮助。
答案 0 :(得分:3)
试试这个:
Dictionary<string, Tuple<string, string>> myDictionary = new Dictionary<string, Tuple<string, string>>();
myDictionary.Add(myKey, new Tuple<string, string>(firstValue, secondValue));
你需要调用Tuple的构造函数。
答案 1 :(得分:1)
Dictionary<string, Tuple<string, string>> myDictionary = new Dictionary<string, Tuple<string, string>>();
myDictionary.Add("key", new Tuple<string, string>("firstValue", "secondValue"));