C#.NET delegate keyword as name of the function to be called using delegate object/constructor

后端 未结 1 1961
Happy的楠姐
Happy的楠姐 2021-01-15 21:39

I am following a book which uses delegate keyword (as per my understanding) as name of the function to be encapsulated in delegate (the one which is called using delegate ob

相关标签:
1条回答
  • 2021-01-15 22:42

    If I understand your question correctly, you're confused with use of the keyword delegate at different places.

    public delegate void AppendChildData(T entityAggregate, object childEntityKeyValue);
    

    The sort answer for the delegate in the above is

    A delegate is a type that defines a method signature. When you instantiate a delegate, you can associate its instance with any method with a compatible signature. You can invoke (or call) the method through the delegate instance. You can find more on MSDN

    In the second case like below

    protected override void BuildChildCallbacks()
      {
       this.childCallbacks.Add("allowances", delegate(Project project, object childKeyName) 
            { 
                  this.AppendProjectAllowances(project); 
            });
      }
    

    delegate is used to declare anonymous method. In one sentence, it is method without name. More description is here MSDN

    And last but not least, in future you should be more specific about your questions. :)

    0 讨论(0)
提交回复
热议问题