SORU
15 EKİM 2010, Cuma


Başka bir Liste değil< olan SERİ bir listedeki öğeleri almak için kullanın<>,;>

Bunu yapmak için basit SERİ bir sorgu var sanıyorum, ama nasıl yapacağımdan pek emin değilim. Lütfen kod parçacığını aşağıda, yorum yapmak istiyorum: açıklar

class Program
{
    static void Main(string[] args)
    {
        List<Person> peopleList1 = new List<Person>();
        peopleList1.Add(new Person() { ID = 1 });
        peopleList1.Add(new Person() { ID = 2 });
        peopleList1.Add(new Person() { ID = 3 });

        List<Person> peopleList2 = new List<Person>();
        peopleList2.Add(new Person() { ID = 1 });
        peopleList2.Add(new Person() { ID = 2 });
        peopleList2.Add(new Person() { ID = 3 });
        peopleList2.Add(new Person() { ID = 4 });
        peopleList2.Add(new Person() { ID = 5 });

        //I would like to perform a LINQ query to give me all
        //of the people in 'peopleList2' that are not in 'peopleList1'
        //this example should give me two people (ID = 4 & ID = 5)
    }
}

class Person
{
    public int ID { get; set; }
}

CEVAP
15 EKİM 2010, Cuma


var result = peopleList2.Where(p => !peopleList1.Any(p2 => p2.ID == p.ID));

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • AutoStream's Garage419

    AutoStream's

    15 EKİM 2007
  • Kamikazeepanda

    Kamikazeepan

    5 ŞUBAT 2006
  • Triune Films

    Triune Films

    9 ŞUBAT 2006