OfType operatörü, bir koleksiyondaki bir öğeyi belirtilen bir türe dönüştürme yeteneğine dayalı olarak koleksiyonu filtreler.
Sorgu Sözdiziminde OfType
Her öğenin türüne göre yukarıdaki koleksiyonu filtrelemek için OfType operatörünü kullanın.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | class Ogrenci { public int ID; public string Ad; public int Yas; } class Program { static void Main(string[] args) { IList arrayList = new ArrayList(); arrayList.Add(0); arrayList.Add("Bir"); arrayList.Add("İki"); arrayList.Add(3); arrayList.Add(new Ogrenci() { ID = 1, Ad = "Hayri",Yas = 17 }); var stringSonuc = from s in arrayList.OfType<string>() select s; var intSonuc = from s in arrayList.OfType<int>() select s; foreach (var item in stringSonuc) { Console.WriteLine(item); } Console.WriteLine("*******"); foreach (var item in intSonuc) { Console.WriteLine(item); } Console.ReadKey(); } } |
Çıktı:
1 2 3 4 5 6 7 | Bir İki ******* 0 3 |











Yorum Yap