Quantcast
Channel: Geeks Tutor
Viewing all articles
Browse latest Browse all 38

Filtering the Odd Numbers from the List of Integers using LINQ

$
0
0

LINQ provides one of the easiest way to find out and filter the odd numbers from the List of Integers in C#.

The below sample code demonstrates the usage of the LINQ Query to achieve the same.

Filtering the Odd Numbers from the List of Integers using LINQ

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace GinktageConsole

{

class Program

{

static void Main(string[] args)

{

List<int> InputList = new List<int> { 24,25,26,11,23};

var OutPutItems = (from item in InputList

where item % 2 != 0

select item).ToList<int>();

foreach (var OutputItem in OutPutItems)

Console.WriteLine(OutputItem);

Console.ReadLine();

}

}

}

Viewing all articles
Browse latest Browse all 38

Trending Articles