元组允许快速地将相关信息组合在一起,而不必为其编写结构或类。这在重构非本地化的代码时非常有用。
然而,初始化一个列表似乎有点多余。
var tupleList = new List<Tuple<int, string>>
{
Tuple.Create( 1, "cow" ),
Tuple.Create( 5, "chickens" ),
Tuple.Create( 1, "airplane" )
};
难道没有更好的方法吗?
Dictionary<int, string> students = new Dictionary<int, string>()
{
{ 111, "bleh" },
{ 112, "bloeh" },
{ 113, "blah" }
};
相似问题