c# - filling List<Tuple<string,string>> with linq -


there list of string this

{'123',  '234',  '345',  '123c',  '456',  '234c'} 

and task create list<tuple<string><string>> , fill every tuple first value 'x' , second value 'xc' example tuple<123,123c> , if there not pair ending 'c' char, put second value null, in tuple tuple<345,null>. there way linq?.

you try this:

var result = list.groupby(word => !word.endswith('c'))                  .select(gr => tuple.create(gr.key, gr.firstordefault(i=>i.contains(gr.key)))); 

essentially, group list elements based on if word ends caracter 'c'. have sequence of keys, words doesn't end character 'c' , associated sequence each of keys words end 'c'. project result in sequence of tuples first element key of gropu , second element corresponding value ends 'c' if exists @ or null if doesn't exists.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -