I have a scenario here where I create a list to check some items, and I need to clear this list inside the loop, and I had some doubts about performance
Should I check the list before cleaning? ( .Any() ou .Count > 0 ?
) to not execute .Clear()
unnecessarily? Or can If worse than Clear?
Move the list creation into the for? (I think it's less efficient, create an instance of the object with each loop.)
Leave as is, call clear without checking if the there is content there.
var gameIds = new List<int?>();
var gameId = gameSession?.GameId % 100000;
for (int i = 0; i < Messages.Count; ++i)
{
var message = Messages[i];
gameIds.Clear();
//.... mais código...
}