Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

.net - What is the maximum number of parameters that a C# method can be defined as taking?

I am trying to figure out what the maximum number of parameters a method in C# can have. I've checked everywhere for an answer, including the C# official documentation, MSDN, and a couple of CLR references and I can't find an answer. Does anyone have an answer to this question?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I used a throwaway program to create a program to determine the maximum number of parameters I can pass to a method. Based on the results of my experimentation, the closest to an answer I can find are the following (all of which is only valid on my computer):

  1. A .net application containing a method with 16383 parameters can be compiled, ran, and called (!)
  2. A .net application containing 16384 or more parameters can be compiled, but running such a program throws an unstated exception.
  3. A .net application containing 50000 parameters can also be compiled, but attempting to run such an application results in a StackOverflowException being thrown.
  4. Attempting to compile a .net application containing 100000 parameters or more results in csc.exe giving a compile-time error, stating that the resulting expression is too long or complex to handle.

Aside from that, does anyone have a definitive answer to this question?

P.S. If anyone wants to try this experiment on their computer, you can start with my test program, which can be downloaded https://docs.google.com/open?id=0B1Q3uRTkbsXic2cwUFpXanNkSk0


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...