How do I get the index of a newly added item in a list in C#?

后端 未结 4 832
半阙折子戏
半阙折子戏 2020-12-19 17:29

When I add an item (an instance of a class) to a list, I need to know the index of the new item. Is it possible with any function?

Example code:

MapT         


        
4条回答
  •  旧巷少年郎
    2020-12-19 18:11

    Class1 newTile = new Class1(num, x*32 + cameraX, y*32 + cameraY);
    MapTiles.Add(newTile);
    int index = MapTiles.IndexOf(newTile);
    

提交回复
热议问题