using System; using System.Collections.Generic; using System.Collections; using System.Linq; namespace linq2 { class TasandiPunkt { int x, y; public TasandiPunkt(int ux, int uy) { x = ux; y = uy; } public int KysiX() { return x; } public int KysiY() { return y; } public override String ToString() { return "(" + x + " " + y + ")"; } } class RuutudeLooja { int kogus; public RuutudeLooja(int uusKogus) { kogus = uusKogus; } public IEnumerable Ruudud() { for (int i = 1; i <= kogus; i++) { yield return i * i; } } } class Klassid { public static void Main(string[] arg) { TasandiPunkt[] punktid = { new TasandiPunkt(3, 5), new TasandiPunkt(4, 6) }; IEnumerable vastus = from p in punktid where p.KysiX() > 3 select p; Console.WriteLine(string.Join(" ", vastus)); IEnumerable vastus2 = punktid.Where(p => p.KysiX()>3); Console.WriteLine(string.Join(" ", vastus2)); Console.WriteLine(string.Join(" ", from p in punktid where p.KysiX() > 3 select p.KysiY())); Console.WriteLine(string.Join(" ", punktid.Where(p => p.KysiX()>3).Select(p=>p.KysiY()))); RuutudeLooja r = new RuutudeLooja(5); Console.WriteLine(string.Join(" ", r.Ruudud().Where(arv => arv > 10))); } } } /* E:\jaagup\11\09\linq>Klassid (4 6) (4 6) 6 6 16 25 */