Such a question, why in the delegate declaration in this example do you need the generic parameters <T1, T2> if they are not in the conjuncture of the method the delegate refers to, that is, all input and output parameters are defined by a specific data type, what determines T1 and T2? (without them an error).

namespace ConsoleApplication14 { delegate bool askUser <T1, T2> (string question, Action<string> action, out int age); class Program { static bool AskUser(string questionText, Action<string> tellUser, out int age) { // метод на который ссылается делегат askUser return false; } 
  • In, so a little bit better, but still take some time to master Markdown and comb the text. - D-side
  • Do not delete questions, especially if they have already been answered. Someone has spent his time and you make the work of this person meaningless. - Nick Volynkin
  • @Nick I understood I was already poked for this in the repeated question, I am very sorry, it's just my first question on the portal and I did not know. This will no longer be the case. - Bulat

1 answer 1

The error occurs due to the fact that you have not assigned anything to the out age parameter.

With assignment, the code is compiled without generic parameters:

 using System; namespace ConsoleApplication14 { delegate bool askUser(string question, Action<string> action, out int age); class Program { static bool AskUser(string questionText, Action<string> tellUser, out int age) { age = 0; return false; } static public void Main() { askUser f = AskUser; } } }