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

前端 未结 9 1718
有刺的猬
有刺的猬 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条回答
  •  南笙
    南笙 (楼主)
    2021-01-30 06:08

    You could use a List.

     var myList = new List();
     myList.Add(new {Tank = new Tank(), AttackingTank = new Tank()});
    
     Console.WriteLine("AttackingTank: {0}", myList[0].AttackingTank);
    

提交回复
热议问题