How to check if there is at least one positive value in a list using Linq with C#

1 Answer

0 votes
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main() {
        var list = new List<int> { -3, -5, -1, 7, -6, -8 };

        bool positive = list.Any(x => x > 0);

        if (positive) {
            Console.WriteLine("There is at least one positive value");
        }
    }
}
   
   
   
   
/*
run:
      
There is at least one positive value
    
*/

 



answered Jul 6, 2023 by avibootz
...