How to pass arguments to delegate in Enumerable::Select
Hello gurus!
Could you please advice how to call delegate with 2 params within Enumerable::Select?
I have understanding how to call function with 1 param (getId sample below), but didn't managed to pass extra params (isIdInCollection func).
It's not possible to me to share someIds List as global var for IsIdInCollection , only way is to pass it as argument.
Re: How to pass arguments to delegate in Enumerable::Select
Actually, what you seem to be looking for is a combination of the methods Enumerable::Select() and Enumerable::Where(). You'd then use a two-step process: First extract the IDs, as you're already doing in your first Select() sample, and then filter that list using Where() with an appropriate predicate based on your someIDs. I don't know of any framework method that does that in a single step.
An alternative approach I see is performing the filtering as a set operation:
Re: How to pass arguments to delegate in Enumerable::Select
You can create delegates referring to practically any function that can have any combination of parameters you like. However, like with any function call, the delegate's signature must match what the function you pass it to (e.g. Enumerable::Where()) expects, so eventually it's that function that determins the decision for the parameter set. There are alternative overloads of Select() and Where() taking a delegate with an additional int parameter over which they pass the item sequence number to the selector function/predicate, so that can base decisions on it, but that's it.
Or do you mean parameterizable predicates which make decisions based on information not known until runtime? They can be represented by a class you create yourself and that exposes a predicate delegate member, for instance something like this: http://forums.codeguru.com/showthrea...ated-predicate. In the meantime I became used to using this sort of predicates quite freqently. They can be of arbitrary complexity, mostly limited by imagination...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Bookmarks