logo CodeStepByStep logo

CollectionMystery1

Language/Type: C# collections List

Write the output produced by the following method when passed each of the following lists:

public static void CollectionMystery1(List list)
{
    for (int i = 0; i < list.Count; i++)
    {
        int n = list[i];
        list.RemoveAt(i);
        if (n % 2 == 0)
        {
            list.Add(i);
        }
    }
    Console.WriteLine(list);
}
{5, 2, 5, 2}
{3, 5, 8, 9, 2}
{0, 1, 4, 3, 1, 3}

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.