c# - Write Delegates without messing up the code -
c# - Write Delegates without messing up the code -
i writing delegates this.
delegate void mymethod(string arg1, string arg2); mymethod mm;
i don't know why needs 2 lines declare single delegate. if class has 20 delegates, need write 40 line of code. can tell me way write in 1 line of code ? in advance.
you're declaring 2 different things here:
the first line declares delegate type calledmymethod
the sec line declares field of delegate type it's of import understand difference, because can work out when want declare new delegate type , when just want declare field of existing delegate type. if class has 20 delegate fields, don't want declare new type each of them. if they've got same signature, utilize single type... or better, utilize 1 of framework types such action<...>
or func<...>
.
action<string, string> mm;
(there action
delegates void
homecoming types, , func
delegates non-void
homecoming types, different numbers of parameters, expressed generically. @ msdn more details.)
c# delegates
Comments
Post a Comment