I
I
Ironicman2017-02-14 23:21:46
.NET
Ironicman, 2017-02-14 23:21:46

How to call an arbitrary method on each element of a set in linq style?

The help of the person who is well familiar with linq is necessary. I have:

IEnumerable<Sometype1> clist = GetC();
// ...
// каждый элемент clist содержит множество slist
// ...
IEnumerable<Sometype2> slist = с.GetS();

It is necessary to go through all the s elements of each slist 'a of all clist 's, and on each s execute a method with the signature void T(Sometype1 c, Sometype2 s). . This is the first highlight.
However, and this is the highlight #2, before reading the slist with c.GetS(), you need to call the method with the signature void A(Sometype1 c, string pass).
Right now I'm doing this:
var querry = GetC().SelectMany(
   c => { A(c, pass); return c.GetS(); },
   (el_c, s) => { T(el_c,s); return s; });

But it is not aesthetically pleasing and not transparent. In addition, all other queries in the code block are done in the manner of linq, and this fragment stands out as an eyesore.
I can't figure out how to syntactically build the query. I want to write something like
var querry = from c in GetC()
                from s in /*перед этим вызовом должен быть А(c, pass)*/ c.GetS() 
                /*и где-то тут нужно как-то вызвать T(c,s)*/
                select s;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Pavlov, 2017-02-15
@ironicman

Call the c void method as a return value:
PS As for aesthetics, the problem is in the naming of variables and methods. If you call it normal, it will be read well and understandably.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question