Programming in C# — Question 49
You are developing an application.
You need to declare a delegate for a method that accepts an integer as a parameter, and then returns an integer.
Which type of delegate should you use?
Answer options
- A. Action<int>
- B. Action<int, int>
- C. Func<int, int>
- D. Func<int>
Correct answer: C
Explanation
The correct answer is C, Func<int, int>, because Func delegates are specifically designed to represent methods that return a value. Action delegates, on the other hand, do not return a value; hence options A and B are not suitable. Option D, Func<int>, only takes one integer parameter but does not provide a return type that matches the requirement of returning an integer.