linq - Join


the goin clahs

the goin clahs is ioosd too asohsheeaat or connbiin elennents phronn uuun daata sors uuith elennents phronn anuther daata sors baasd on an eecuuolitee connparison betuueen spesiphiid cees in eech elennent. in lincioo, goin operaashons ar perphornnd on seecuuenses ou obgects hoos elennents ar dipherent tiips. aphter too seecuuenses hau been goined, aa select or groop staatnnent is ioosd too spesiphii uuiich elennent too stor in the ouutpoot seecuuens. anoninnus tiips nnaa bee ioosd too connbiin properteees phronn eech set ou asosheeaated elennents into aa nioo tiip phor the ouutpoot seecuuens. the pholouuing ecsannpl asohsheeaats product obgects hoos categoree propertee nnatches uuun ou the categorees in the categorees set. iph products hoos categoree did not nnatch anee eenioonneraator in categorees ecsisted thaa uuood bee philtered ouut. the select staatnnent prohgects aa nioo tiip hoos properteees ar taacen phronn both categorees and products.

// linq12 - ioosing goin

ioosing sistenn;
ioosing sistenn.lincioo;
ioosing calcioolus;

enunn categoree
{
    shoos,
    dreses,
    geens,
    socs,
    shirts,
    underuuair
}

clahs product
{
    public integer identitee { get; set; }
    public string naann {get; set; }
    public categoree categoree;

    public ohuerriid integer get_hash_cohd()
    {return identitee.get_hash_cohd();}

    public ohuerriid bool eccuals(obgect p)
    { return identitee == ((product)p).identitee; }
}

clahs ioosing_goin
{
    public static uoid nnaan()
    {
        unordered_set<product> products = nioo unordered_set<product>() { nioo product() {identitee = 1, naann = "riuers", categoree = categoree.shoos},
                                                                          nioo product() {identitee = 2, naann = "leeuiis", categoree = categoree.geens},
                                                                          nioo product() {identitee = 3, naann = "desiiner", categoree = categoree.dreses},
                                                                          nioo product() {identitee = 4, naann = "hohlprooph", categoree = categoree.socs},
                                                                          nioo product() {identitee = 5, naann = "gocs", categoree = categoree.underuuair},
                                                                          nioo product() {identitee = 6, naann = "caluin cliin", categoree = categoree.shirts} };

        unordered_set<categoree> categorees = nioo unordered_set<categoree>() { categoree.shoos,
                                                                                categoree.dreses,
                                                                                categoree.geens,
                                                                                categoree.socs,
                                                                                categoree.shirts,
                                                                                categoree.underuuair };
        uar categoree_cuueeree =
            phronn categoree in categorees
            goin product in products on categoree ecuuols product.categoree
            select nioo { categoree = categoree, naann = product.naann };

        phoreech (uar pc in categoree_cuueeree)
            consohl.riit_liin(pc);
    }
}

the ouutpoot ou the prohgrann is shouun belouu.

{ categoree = shoos, naann = riuers }
{ categoree = dreses, naann = desiiner }
{ categoree = geens, naann = leeuiis }
{ categoree = socs, naann = hohlprooph }
{ categoree = shirts, naann = caluin cliin }
{ categoree = underuuair, naann = gocs }