Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

linq - C# : How to get running combination from two List<String> based on a master list -


dear , previous question how moving combination 2 list<string> in c#?

i'm having masterlist , 2 childlist below

        list<string> masterlist = new list<string> { "a", "b", "c", "d", "e" };         list<string> listone = new list<string> { "a", "b", "c" };         list<string> listtwo = new list<string> { "b", "d" }; 

i need running combination above list i'm using like(previous question's answer(thanks danny chen))

        list<string> result = new list<string>();         result = listone.selectmany((a, indexa) => listtwo                                     .where((b, indexb) => listtwo                                     .contains(a) ? !b.equals(a) && indexb > indexa :                                      !b.equals(a)).select(b => string.format("{0}-{1}", a, b))).tolist();  

so result list contain

        "a-b"         "a-d"         "b-d"         "c-b"         "c-d" 

now problem sorting issue

in above result fourth entry c-b should b-c. because in masterlist c after b.

how in existing linq .

please me this.

not clear on exact requirement here, masterlist dictate of 2 items should appear first? order of x1-x2 list? i.e. should b-c appear before b-d because c appears before d in masterlist?

anyway, here's produces result you've asked far:

list<string> masterlist = new list<string> { "a", "b", "c", "d", "e" }; list<string> listone = new list<string> { "a", "b", "c" }; list<string> listtwo = new list<string> { "b", "d" };  listone.selectmany(i =>  listtwo.where(i2 => != i2)        .select(i2 =>              {                 if (masterlist.indexof(i) < masterlist.indexof(i2))                     return string.format("{0}-{1}", i, i2);                 else                     return string.format("{0}-{1}", i2, i);             }        )); 

outputs:

a-b a-d b-d b-c c-d 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -