[英]How to pass ref parameters in params
I want to pass n
number of parameters to a method (both reference and normal). 我想将
n
个参数传递给方法(引用和常规)。 Here is my source code 这是我的源代码
static void testParams(params object[] parameters)
{
for (int index = 0; index < parameters.Length; index++)
{
Console.WriteLine(parameters[index ].gettype();
}
}
Its working fine when I used as 当我用作
int i=0, j=0;
double k=0.0;
testParams(i,j,k)
but i want it like, 但是我想要
int i=0, j=0;
double k=0.0;
testParams(i,j,ref k)
How to do this, please help me... 怎么做,请帮我...
You cannot. 你不能。 If you want to pass a parameter by reference, the method should have a ref in its definition.
如果要通过引用传递参数,则该方法的定义中应具有ref。
For example 例如
static void Mymethod(ref int i)
can be called by 可以被称为
int localvariable = 5;
Mymethod(ref localvariable);
but your method definition cannot be 但您的方法定义不能是
static void Mymethod(int i)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.