Getting an index out of range error message on line 49 "if (myNumber == myPartyAges[i])" I can't figure out why. using Visual studio basic set up here is the code:
List<int> myPartyAges = new List<int>() { 24, 44, 54, 39, 17, 24, 21 };
int myNumber = myPartyAges[5];
bool contains = false;
for (int i = myPartyAges[5] - 1; i >= 1; i--)
{
if (myNumber == myPartyAges[i])
{
contains = true;
break;
}
}
if (contains == true)
{
Console.WriteLine("Number found.");
}
else
{
Console.WriteLine("Number not found.");
}