Learning C# and i'm trying to find the second largest array in a user-inserted list. I found a solution online:
int second = int.MinValue;
foreach (int i in playerScore)
{
if (i > largest)
{
second = largest;
largest = i;
}
else if (i > second)
second = i;
}
But the problem is, if the two largest number are the same the loop still spit out the largest number. I can't think of a way to edit this loop so it finds the true second highest number in my array. Would a loop like this even be the most efficient way of doing this?
Thanks