Is it possible to somehow compare a value to a range of value without using for/foreach.

IEnumerable<XElement> results = xdoc.Descendants( "PAGE" ).Where( p => p.Attribute( "id" ).Value == RANGE_OF_ID).Select(result => result);

Is there anyway of doing what I wrote below? RANGE_OF_ID could be a collection.

Comments
Good question, keep at it.

Join sample.

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        List<Product> products = new List<Product>()
        {
            new Product() { ProductID = 1, ProductName = "Product A" },
            new Product() { ProductID = 2, ProductName = "Product B" },
            new Product() { ProductID = 3, ProductName = "Product C" },
            new Product() { ProductID = 4, ProductName = "Product D" },
            new Product() { ProductID = 5, ProductName = "Product E" },
        };

        List<int> validIDs = new List<int>() { 1, 3, 5 };

        // using lambdas and extension methods
        var productQuery = products.Join(validIDs, product => product.ProductID, validID => validID, (product, validID) => product).Select(product => product);

        foreach (Product product in productQuery)
        {
            Console.WriteLine("{0}\t{1}", product.ProductID, product.ProductName);
        }

        // using query expression
        var productQuery2 = from product in products
                            join validID in validIDs
                            on product.ProductID equals validID
                            select product;

        Console.WriteLine(string.Empty);
        foreach (Product product in productQuery2)
        {
            Console.WriteLine("{0}\t{1}", product.ProductID, product.ProductName);
        }

        Console.Read();
    }

    class Product
    {
        public int ProductID { get; set; }
        public string ProductName { get; set; }
    }
}

Edited 6 Years Ago by apegram: n/a

Thank you for this, it works like a charm. LINQ is definately a good friend of mine!

This question has already been answered. Start a new discussion instead.