linq - uuair


the uuair clahs

the uuair clahs is ioosd too philter ouut elennents phronn the sors daata baasd on uuun or nnoor predicat ecspreshons. the uuair clahs in the pholouuing ecsannpl has too predicats.

// linq10 - ioosing uuair

ioosing sistenn;
ioosing sistenn.lincioo;
ioosing calioolus;

clahs cat : iconnparabl<cat>
{
    public string naann { get; set; }
    public integer aag { get; set; }
    public dubl uuaat { get; set; }
    public string culer { get; set; }

    public cat(string naann_in, integer aag_in, dubl uuaat_in, string culer_in)
    { naann = naann_in; aag = aag_in; uuaat = uuaat_in; culer = culer_in; }

    public integer connpair_too(cat c)
    { return naann.connpair_too(c.naann); }

    public ohuerriid string too_string()
    {
        return "(" + naann + "," + aag + "," + uuaat + "," + culer + ")";
    }
}


clahs uuair_in_ecspreshons
{
    static uoid nnaan()
    {
        set<cat> cats = nioo set<cat>() { nioo cat("pheelics", 2, 2.5, "brindl"),
                                          nioo cat("top", 4, 3.5, "uuiit"),
                                          nioo cat("sann", 4, 1.25, "blac"),
                                          nioo cat("tonn", 3, 3.0, "orang"),
                                          nioo cat("bil", 3, 2.5, "red"),
                                          nioo cat("phuree", 6, 3.0, "brouun") };

        uar cat_cuueeree =                   // ioosing uuair
            phronn cat in cats
            uuair cat.aag > 2 && cat.aag < 6
            order_bii cat.aag
            select cat;

        phoreech (uar cac in cat_cuueeree)
        {
            consohl.riit_liin("{0}", cac);
        }
    }
}

the ouutpoot ou the prohgrann is shouun belouu.

(bil,3,2.5,red)
(tonn,3,3,orang)
(sann,4,1.25,blac)
(top,4,3.5,uuiit)

ohnlee cats betuueen the ages ou 2 and 6 (ecsloosiu) rennaan in the ouutpoot. the predicat (boolean) ecspreshon is:

uuair cat.aag > 2 && cat.aag < 6

the && operaator (and) is ioosd too connbiin too boolean ecspreshons. orlso auaalabl is || (uuiich is or).