I have the example below, I want to cancel LINQ how to write ?

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

        // See if any elements with values greater than 10 exist.
        bool exists = list.Exists(element => element > 10);
        Console.WriteLine(exists);

        // Check for numbers less than 7.
        exists = list.Exists(element => element < 7);
        Console.WriteLine(exists);
    }

Recommended Answers

All 5 Replies

Don't know why you want to do that.
You would have to write more code with a foreach and if statement.

I'm learning two LINQ writings and no LINQ but I have not figured out how to write without using LINQ so i'm asking you. So, do you think of writing without LINQ ?

If you absolutely want to do it without LINQ you could do something like this:

foreach (var element in list)
{
    if (element > 10)
    {
       exists = true;
    }
    else
    {
       exists = false;
    }
}

I'd rather like the lambda syntax, but if you want get verbose, be my guest. :)

thank you

thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.