less than operator not working correctly

mp3909

Well-known member
Joined
Apr 22, 2018
Messages
61
Location
UK
Programming Experience
3-5
why does 13 get printed out in the code below?
13 is not less 13 so it should not be be printed out, right?

C#:
using System;
using System.Collections.Generic;

delegate void FooDelagate(string xx);

class Program
{

    public static void Main()
    {
        List<int> L = new List<int>();
        L.Add(7);
        L.Add(11);
        L.Add(17);
        L.Add(13);

        IEnumerable<int> result = GetNumbersLessThanThirteen(L);

        foreach(int s in L)
        {
            Console.WriteLine(s);
        }
    }

    public static IEnumerable<int> GetNumbersLessThanThirteen(List<int> numbers)
    {
        foreach(int n in numbers)
        {
            if(n<13)
            {
                yield return n;
            }
        }
    }
}
 
Last edited by a moderator:
What are you doing in this part of code foreach(int s in L) ?
 
Back
Top Bottom