You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The guide makes recommendations about delegate style, but not when to use them. I feel like it suggests that they should be used, when, for the examples given, Action is a simpler choice. (A couple Unity forum users and I had a brief discussion five years ago which might give some insight.)
I can think of two cases where I would use a named delegate.
Clarity for curried methods. Probably outside the scope of this guide.
When the delegate takes at least one parameter. This should go in the style guide if the raywenderlich.com style is to use named parameters. I believe everyone should, but realize that's contentious.
delegatevoid DoMeaningfulThings(intcount,stringname);staticvoidFunctionWithSameSignature(intcount,stringname){}staticvoidUnimportantFunction(){// Unimportant values.varcount=11,name="Jane Doremi";DoMeaningfulThingsdoMeaningfulThings=(count,name)=>{// meaningful things are done here};// Why you'd use a custom delegate instead of an Action<int, string>:// parameter names from the delegate are usable.
doMeaningfulThings(count: count, name: name);// Compiles, but lacks clarity.
doMeaningfulThings(count, name);// Compiles.Action<int,string>action= FunctionWithSameSignature;
action(count, name);// Neither compiles. Actions can't carry parameter names.
action(count: count, name: name);action=doMeaningfulThings;}
If you don't want to take on named parameters at this point, I would suggest a "Prefer Action and Func" guideline, or an argument against using them in all cases.
The text was updated successfully, but these errors were encountered:
The guide makes recommendations about delegate style, but not when to use them. I feel like it suggests that they should be used, when, for the examples given, Action is a simpler choice. (A couple Unity forum users and I had a brief discussion five years ago which might give some insight.)
I can think of two cases where I would use a named delegate.
If you don't want to take on named parameters at this point, I would suggest a "Prefer Action and Func" guideline, or an argument against using them in all cases.
The text was updated successfully, but these errors were encountered: