How to List Odd Numbers from a List of Integers using Lambda Expression in C#?

Published on February 25, 2014 by abundantcode

Filed under LINQ

Last modified February 25, 2014

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3938 times

Are you looking out for a simple logic to retrieve the odd numbers from the list of integers using Lambda Expression in C#? Below is a sample code snippet demonstrating how to do it.

How to List Odd Numbers from a List of Integers using Lambda Expression in C#?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACSampleCode
{
    class Program
    {
        static void Main(string[] args)
        {
            // List out the odd numbers from a list of integers using Lambda Expression
            List LstACValues = new List { 1, 7, 2, 5, 10, 16 };
            var result = LstACValues.Where(a => a % 2 != 0).ToList();
            foreach (var item in result)
                Console.WriteLine(item);
            Console.ReadLine();
        }
    }
}

How to List Odd Numbers from a List of Integers using Lambda Expression in C#?

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

VB.NET and Lambda – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

C# and Lambda – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

VB.NET and Lambda – Filter elements from object collection using where clause

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...