Anonymous inner classes in C#

前端 未结 3 2144
后悔当初
后悔当初 2020-12-10 10:55

I\'m in the process of writing a C# Wicket implementation in order to deepen my understanding of C# and Wicket. One of the issues we\'re running into is that Wicket makes h

3条回答
  •  青春惊慌失措
    2020-12-10 11:33

    You can make the delegate be part of the constructor of the Link class. This way the user will have to add it.

    public class Link 
    {
        public Link(string id, Action handleStuff) 
        { 
            ...
        }
    
    }
    

    Then you create an instance this way:

    var link = new Link("id", () => do stuff);
    

提交回复
热议问题