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 called mymethod 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

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -