How to find the negative double numbers from a list of objects and sort them using Linq in C#

1 Answer

0 votes
using System;
using System.Linq;
using System.Collections.Generic;
  
class Program
{
    static void Main() {
        var list = new List<object> {3.14, -5.31, "c#", 8.18, "c", -99.17, 10, "c++", -5, -0.19};

        List<double> result = list.OfType<double>().Where(d => d < 0).ToList();

        Console.WriteLine(String.Join(", ", result));
    }
}
  
  
  
/*
run:
     
-5.31, -99.17, -0.19
   
*/

 



answered Sep 27, 2023 by avibootz

Related questions

...