classA { Public intID {Get;Set; } Public stringName {Get;Set; } } classB { Public intID {Get;Set; } Public intAge {Get;Set; } } classC { Public intID {Get;Set; } Public stringAddress {Get;Set; } } Private voidButton8_click (Objectsender, EventArgs e) {List<A> ListA =NewList<a>(); List<B> Listb =NewList<b>(); List<C> LISTC =NewList<c>(); for(inti =0; I <Ten; i++) {Lista.add (NewA () {id = i, name ="name"+i.tostring ()}); Listb.add (NewB () {id = i, age = -+i}); Listc.add (NewC () {id = i, address ="Address"+i.tostring ()}); } varKK = fromAinchListA Join BinchListb on a.id equals b.id//JOIN OperationJoin CinchLISTC on a.id equals c.id//JOIN Operation whereA.name.indexof ("name") >=0 //where Operation Select New { //Reorganize ColumnsID =a.id, name=A.name, age=B.age, Address=c.address}; StringBuilder SB=NewStringBuilder (); foreach(varOinchKK) {sb. Append (O.id+" "+ O.name +" "+ O.age +" "+ o.address +"\ n"); } richTextBox1.Text=sb. ToString (); }
Join operations on multiple objects using LINQ C #