With anonymous function in C# 4.0 why can't I define a delegate inline
What are the pro cons with having delegates having a reserved definition type.
For example in c if I want to define a function that takes a pointer to a function I can simply define
void F(bool (*pFn)(int));
In c# I have to take the extra step of first defining the delegate type similar if I had to create a typedef in c before I could define the above function
delegate bool del(int s);
void F(del d){...}
I find the c# style to bee less clear and flexible.
A: Am I not realizing that this is doable in C#
B: Would this be a poor language feature to add by introducing the complexity of c type declaration system.Let me clarify I know the fucn is available i'w wondering if there is a way to define an arbitrary delegate开发者_StackOverflow社区.
Func in .NET 3.5 will let you have up to 4 in parameters and 1 return value. Func in .NET 4 will let you have up to 16 in parameters and 1 return value. If you need more than that you probably should get a quantum computer.
Also Action has the same limits in .NET 3.5 and .NET 4 with the exception of the return value.
How about this?
void F(Func<int, bool> d){...}
精彩评论