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();
}
}
}
Related Articles
How to Compare two Array of Bytes for Equality in C#?
LINQ to Twitter Runs On Xamarin.iOS
Beginning LightSwitch in VS 2013 Part 4: Too much information! Sorting and Filtering Data with Queries
5 LINQ for JavaScript Libraries
Interesting .NET Links – May 17 , 2011
Interesting .NET Links – May 8 , 2011
Interesting .NET Links – May 6 , 2011
Interesting .NET Links – April 1 , 2011
Interesting .NET Links – March 29 , 2011
Interesting .NET Links – March 14 , 2011
Interesting .NET Links – February 10 , 2011
Interesting .NET Links – February 9 , 2011
Interesting .NET Links – February 07, 2011
Interesting .NET Links – January 31, 2011
Interesting .NET Links – January 11, 2010
Interesting .NET Links – January 4 , 2011
Interesting .NET Links – January 1 , 2011
Interesting .NET Links – December 16 , 2010
Interesting .NET Links – October 28, 2010
Interesting .NET Links – 21st October , 2010