Is there a trick in creating a generic list of anonymous type?

前端 未结 9 1789
有刺的猬
有刺的猬 2021-01-30 05:25

Sometimes i need to use a Tuple, for example i have list of tanks and their target tanks (they chase after them or something like that ) :

List

        
9条回答
  •  旧时难觅i
    2021-01-30 06:03

    Or even more simple

            var tupleList = (
               new[] {
                    new { fruit = "Tomato", colour = "red"},
                    new { fruit = "Tomato", colour = "yellow"},
                    new { fruit = "Apple", colour = "red"},
                    new { fruit = "Apple", colour = "green"},
                    new { fruit = "Medlar", colour = "russet"}
                }).ToList();
    

    Which loses the static function.

提交回复
热议问题