本文介绍了是什么的参数为C#方法可以定义为服用的最大数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出参数的最大数量在C#中的方法可以有什么。我检查无处不在的答案,包括C#官方文档,MSDN,和一对夫妇的CLR引用,我无法找到答案。有没有人有这个问题的答案?

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?

推荐答案

为了推动方法的参数压入堆栈,编译code具有以下MSIL运codeS可供选择:

In order to push method arguments onto the stack, compiled code has the following MSIL opcodes to choose from:

ldarg

ldarg.0

ldarg.1

ldarg.2

ldarg.3

ldarg.S

ldarg.0 ldarg.3 推前4个参数(包括为实例方法的第一个参数)。

ldarg.0 to ldarg.3 pushes the first 4 parameters (including this as the first argument for instance methods).

ldarg.S 需要一个8位的参数编号。

ldarg.S takes an 8 bit argument number.

这给我们留下了普通的老式 ldarg ,它提供了最大的参数:一个无符号16位的参数编号。所以,最大数量的参数,可以成功地编译为 2 ^ 16 - 1 = 65,535

That leaves us with plain old ldarg, which offers the largest parameter: an unsigned 16 bit argument number. So the largest number of arguments that can be successfully compiled is 2^16 - 1 = 65,535.

由于约努茨Hulub注意到并rmiesen在经历了对方的回答,但是,也有适用时,实际上是试图执行你的方法取决于系统的平台/架构各种实际堆栈大小的限制。基于rmiesen的回答,可以有把握地说,目前的.NET实现限制参数编号为无符号14位数字。

As Ionut Hulub noted and rmiesen has experienced in the other answer, however, there are various practical stack size limits that apply when actually trying to execute your method depending on the platform/architecture of the system. Based on rmiesen's answer, it is safe to say that the current .NET implementation limits the argument number to an unsigned 14 bit number.

这篇关于是什么的参数为C#方法可以定义为服用的最大数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 14:17