I have a program that calculates some values and saves them to an array. Before save a value, program checks if there is already an identical value in array:
string someData = GetData();
bool newItem = true;
int arrayDataLength = arrayData.Length;
for (int x = 0; x < arrayDataLength; x++)
{
if (arrayData[x] == someData)
{
newItem = false;
arrayDataCount[x]++;
break;
}
}
if (newItem == true)
{
Array.Resize(ref arrayData, (arrayDataLength + 1));
Array.Resize(ref arrayDataCount, (arrayDataLength + 1));
arrayData[arrayDataLength] = someData;
arrayDataCount[arrayDataLength]++;
}
Sometimes arrays with data become big, and program works a bit slow. How can I optimize perfomance of this action?