【发布时间】:2020-06-20 06:22:38
【问题描述】:
我知道我们可以像这样声明一个命名元组:
var name = (first:"Sponge", last:"Bob");
但是,我不知道如何将命名元组与泛型类型(例如 Dictionary)结合起来。
我尝试了以下变体,但没有运气:
Dictionary<string, (string, string)> name = new Dictionary<string, (string, string)>();
// this assignment yields this message:
// The tuple element name 'value' is ignored because a different name or no name is specified by the
// target type '(string, string)'.
// The tuple element name 'limitType' is ignored because a different name or no name is specified
// by the target type '(string, string)'.
name["cast"] = (value:"Sponge", limitType:"Bob");
// I tried putting the name in front and at the end of the type, but no luck
// Both statements below produce syntactic error:
Dictionary<string, (value:string, string)> name;
Dictionary<string, (string:value, string)> name;
有谁知道 C# 是否支持上述场景?
【问题讨论】:
标签: c# dictionary generics tuples