Get Ice Creams with price less than 10 in CSharp

Description

The following code shows how to get Ice Creams with price less than 10.

Example


      /*  ww  w. j  a  v  a 2  s .  c om*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Xml.Linq;

class Program
{
    static void Main(string[] args)
    {
        List<Icecream> icecreamsList = new List<Icecream> 
            {
              new Icecream {Name="A", Price=10.5 },
              new Icecream {Name="B", Price=9.80 },
              new Icecream {Name="C", Price=7.5 }
            };

        IEnumerable<Icecream> i = from ice in icecreamsList where ice.Price < 10 select ice;
        foreach (Icecream ice in i)
        {
            Console.WriteLine("{0} is {1}", ice.Name, ice.Price);
        }

    }
}

public class Icecream
{
    public string Name { get; set; }
    public double Price { get; set; }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ