2013-07-19 346 views
0

我想将n参数数量传递给方法(参考和正常)。 这里是我的源代码如何在参数中传递参数

static void testParams(params object[] parameters) 
    { 
     for (int index = 0; index < parameters.Length; index++) 
     { 
      Console.WriteLine(parameters[index ].gettype(); 
     } 
    } 

其工作正常,当我作为

int i=0, j=0; 
double k=0.0; 
testParams(i,j,k) 

,但我希望它像,

int i=0, j=0; 
double k=0.0; 
testParams(i,j,ref k) 

如何做到这一点,请帮助我..

+2

简短的回答是你不能。你想用这个完成什么?您提供的代码中没有任何内容表明您需要'ref'参数。 –

+1

可能重复的[有趣的“参数参数”功能,任何解决方法?](http://stackoverflow.com/questions/1776020/interesting-params-of-ref-feature-any-workarounds) – shf301

+0

@pswg:它是只是一个示例代码。我需要将这些参数传递给可能建在'LAB VIEW' –

回答

1

你不能。如果您想通过引用传递参数,则该方法应该在其定义中具有ref。

例如

static void Mymethod(ref int i) 

可以通过

int localvariable = 5; 
Mymethod(ref localvariable); 

叫,但你的方法定义不能

static void Mymethod(int i)