Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Func and Action Delegates only take 4 arguments?

Tags:

c#

Why 4? I know its in the documentation as 4, but that just seems strange.

like image 587
jf26028 Avatar asked Feb 06 '26 09:02

jf26028


2 Answers

I'll go out on a limb and say it's because someone needed an Action or Func delegate somewhere in the framework with 4 arguments and no one has yet needed one with 5. Alternatively, someone decided that any more than 4 and you ought to introduce a class to hold the values instead as @chadmyers says.

like image 95
tvanfosson Avatar answered Feb 07 '26 22:02

tvanfosson


I don't know the exact answer, but I'm guessing it has to do with the fact that if you are passing around delegates with >4 arguments, that's a code smell and you're likely doing something wrong. You should consider using the "Introduce Parameter Object" refactoring.

like image 45
Shivaansh Gupta Avatar answered Feb 07 '26 23:02

Shivaansh Gupta