Which is a better approach to run operations
- Use Delegate
- Use Action
- Use Predicate
- Use Func
Which once is the best in terms of performance, memory and code maintainability.
Which is a better approach to run operations
Which once is the best in terms of performance, memory and code maintainability.
As with most things programming, it depends. Are you trying to run async operations? Multithreaded operations? Are you dealing with events? Your name 'WPF User' suggests that you're using .NET.
Probably not what you want to hear but,
It all depends.
Using Predicate<>
is a good idea in the specific applications that it is fit for (but it is also the same as Func<T, bool>
).
If you can use Func<>
(or its return-less cousin Action<>
) then go for it. It's always better to re-use what is already there rather than re-invent the wheel.
If all else fails, fall back on delegate
. There's nothing wrong with it and it still works great.
I don't think you're going to find that any one of those consistently performs any better in terms of speed or memory consumption since their performance is going to be dictated by what code you're running inside them.
Just pick what works for your needs and move on. If there's a performance issue at some point down the road...worry about it then. Code first, optimize later.