简体   繁体   中英

What is the maximum number of parameters for a method (WebApi ? )

I have this method in WebApi

[IHttpActionResult]
[Get]
public void GetSome(P1, P2 ....... Pn)
{
   ...///
}

Just curious:

Any ideas, what is the maximum number of parameters allowed by WebApi for this method ?

You mean technically or practically? :p

The C# method parameter limit is 65,535. Most browsers only support an URL of 2000 to 4000 characters. Depending on the consumer of your API, there might be some restrictions there as well.

But most importantly: what are you trying to do? Seriously?

You're creating an API, simple methods that are easy to understand should be your main goal. I'm not sure a method with 65000 parameters would be anywhere near simple.

To me this sounds like step 1 of a walk down "OMG kill this code" lane :)

There are few similar Q & A around Internet and Stack overflow . Which is asked to know the C# Method maximum number of parameters . The same will be applicable in your case as well.

Cases:

  • A .net application containing a method with 16383 parameters can be compiled, ran, and called (!)
  • A .net application containing 16384 or more parameters can be compiled, but running such a program throws an unstated exception.
  • A .net application containing 50000 parameters can also be compiled, but attempting to run such an application results in a StackOverflowException being thrown.
  • 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 .

Note:

  • Those numbers depend on the architecture of the operating system and the memory of the computer .

  • From Browser side it may vary. It may be allow less or more than this count.

Similar Q & A :

C# Method Maximum Number of Parameters

Acceptable Parameters Count for a C# Method

Passing required and less number of parameters to the Method will be the best coding practice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM