Delegate function with params
Hello, is it possible to somehow have "named" parameters in the delegate function?
Right now I have:
But that way you have to remember that the first argument is the actual number and the second argument is the expected value for example (In this case it doesn't matter, but let's say we have 3+ args..)
My question is:
Is it possible to have the usage like this somehow? Or using some other approach?
14 Replies
Change the delegate to not take
params T[] args
?I need to take the function from user and I only know that the return type is bool and that any number of params is T type. But I don't know how many params
okay, then the answer is no
Ah okay. Then this must be enough 😄
you can ofc do somethng like
, but that doesnt help the external usage
Yeah, I'm thinking about just supporting limited number of parameters, just as it is with the generic Func<> where you can only have up to 16 params
sure
Like this:
mhm
thats much better, if you ask me
But then I would have to overload x number of times the generic method. So I would have:
And I then I would have to somehow decide which function was actually provided and call that
So I would have X number of variables with these functions I guess?
yeah
btw
Func<T, bool>
is the same as Predicate<T>
Cool, didn't know about that one. Thanks
I guess sacrificing the complexity of the "library" is better for the comfort of user defined functions.
yes, absolutely
thats half the point of libraries 🙂
Okay, thank you for your opinion ❤️