How to find integer numbers in a list of objects using LINQ with C#

1 Answer

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

class Program 
{
   static void Main(string[] args) 
   {
        List<object> list = new List<object> { "c#", 909, "LINQ", 4, "200", 89, 'c', 700 };
      
        var integers = list.OfType<int>();

        foreach (int n in integers) {
            Console.WriteLine(n);
        }
   }
} 



 
/*
run:
   
909
4
89
700
    
*/

 



answered Apr 15, 2024 by avibootz
...