C#C
C#2y ago
milan

Get first item in list

I am having a very strange bug with my List<>
The following code works as intended - resulting tallyTotal of first person in possiblePeople :
c#
{
            Person selectedPerson;
            List<Person> possiblePeople = new List<Person>();

            foreach (Person person in people)
            {
                if(person.tallyTotal == Person.tallyBaseline)
                {
                    possiblePeople.Add(person);
                }
            }
            possiblePeople.Sort((x, y) => string.Compare(x.lastName, y.lastName));

            consoleOutput.Text = possiblePeople[0].tallyTotal.ToString();
}

just changing the last line breaks it:
c#
possiblePeople[0].tallyTotal += 1;

it provides the attached error (image)
image.png
Was this page helpful?