C#;使用字符串元组设置字典中的键和值

C#;使用字符串元组设置字典中的键和值,c#,dictionary,initialization,tuples,C#,Dictionary,Initialization,Tuples,我是C#的新手,所以请相应地指导。我有以下声明: Dictionary<string, Tuple<string, string>> myDictionary = new Dictionary<string, Tuple<string, string>>(); Dictionary myDictionary=newdictionary(); 我想将元组的键和字段设置为: myDictionary.Add( myKey, Tuple<fir

我是C#的新手,所以请相应地指导。我有以下声明:

Dictionary<string, Tuple<string, string>> myDictionary = new Dictionary<string, Tuple<string, string>>();
Dictionary myDictionary=newdictionary();
我想将元组的键和字段设置为:

myDictionary.Add( myKey, Tuple<firstValue, secondValue> );
myDictionary.Add(myKey,Tuple);
其中firstValue和secondValue是将作为另一个字典的键的字符串。我想要一些关于.Add()方法中元组初始化语法的帮助。

试试以下方法:

Dictionary<string, Tuple<string, string>> myDictionary = new Dictionary<string, Tuple<string, string>>();

myDictionary.Add(myKey, new Tuple<string, string>(firstValue, secondValue));
Dictionary myDictionary=newdictionary();
Add(myKey,新元组(firstValue,secondValue));
您需要调用元组的构造函数。

Dictionary myDictionary=newdictionary();
    Dictionary<string, Tuple<string, string>> myDictionary = new Dictionary<string, Tuple<string, string>>();

myDictionary.Add("key", new Tuple<string, string>("firstValue", "secondValue"));
添加(“key”,新元组(“firstValue”,“secondValue”);
Tuple.Create()通常比较容易看。多亏了M.Pillapan。正是我需要的。作为参考,我缺少在
Add
方法中将
Tuple
声明为
code
的概念。