1) What is the real definition for Action delegate? some definitions describe it is as polymorphic conditional map , some say it *Applied decision Table *.
(You may ask what will you achieve by knowing definition , if i know it i can understand its real purpose).
2) Thanks Binary Worrier,Andrew Hare of stackoverflow for giving nice examples.
When i declare
string[] words = "This is as easy as it looks".Split(' ');
`Array.ForEach(words, p => Console.WriteLine(p));`
i can understand what it actually does.But when i declare ,How does C# interpret when i
declare
Dictionary<SomeEnum, Action<User>> methodList =
new Dictionary<SomeEnum, Action<User>>()
methodList.Add(SomeEnum.One, DoSomething);
methodList.Add(SomeEnum.Two, DoSomethingElse);
Does it store collections of Actions in dictionary ?.unfortunately as the example was incomplete i did not get it.
3) What is the functional difference between Action , Function ,Predicate delagets?
It’s just another delegate.
Action<T>is declared like this:It’s just “something which acts on a single item”. There are generic overloads with more type parameters and normal parameters. In itself, an
Action<T>isn’t an applied decision table or anything like that – it’s just a delegate which can do “something” with an item.The dictionary example is just a dictionary with enum values as keys, and actions as values – so you can look up what to do based on the enum value, and then pass in a
Userreference for it to act on.As for
FuncvsActionvsPredicate:Funcis likeAction, but returning a value.Predicateis similar, but always returnsbool, and there aren’t the range of generic overloads, justPredicate<T>to determine if an item “matches” the predicate.