Hey guys I currently have a sports sim which stores its statistics in classes which contains all the information needed (e.g. where the hit went, result of the hit, who hit it, what stage of the game was the hit performed etc.) Im storing these class instances in a list and want to search these lists as a way to display the stats during the match. I have been playing around with some loops and found some information through searching of using Linq but saw it doesn't have the best performance and Im working on predominantly a mobile game! Any help pointing me out in the right direction would be much appreciated! Aden
Don't overthink it: just write the code to iterate the classes and do the sums/tallies you need. I can't imagine you'll run into performance issues until you have hundreds of thousands of items to iterate over. Computers are pretty fast.
Plus one for trying the nieve approach first. Often that's enough. Also figure out how you can cache results. A search can take as long as it needs to if you only ever do it once.
Thanks guys! At the moment it looks like this Code (CSharp): foreach (var stat in statistics) { // statistics is the list of classes if (stat.playerID == 6) { //ability to add various or statements (playerId + skillType/SkillResult)? statisticOutput.Add(stat); print(statisticOutput.Count); } } If I have other conditions which I want to count is it as easy as just adding the various conditions I need to the loop? Also is it easy enough to grab the index of the list position of the class from this equation?