猿问

字典中的命名元组?

我正在尝试创建一个带有字符串键和元组值(字符串,布尔值)的字典。我想让元组成为一个命名的元组,比如:


Dictionary<string, (string, bool)> spColumnMapping = new Dictionary<string, 

(string, bool)>();

是否可以?


倚天杖
浏览 190回答 1
1回答

慕姐4208626

void Main(){&nbsp; &nbsp; Dictionary<string, (string Foo, bool Bar)> spColumnMapping = new Dictionary<string, (string, bool)>();&nbsp; &nbsp; spColumnMapping.Add("foo", ("Quax", false));&nbsp; &nbsp; var x = spColumnMapping["foo"];&nbsp; &nbsp; Console.WriteLine(x.Foo); // prints Quax&nbsp; &nbsp; Console.WriteLine(x.Bar); // prints False}只需在类型后命名参数。
随时随地看视频慕课网APP
我要回答