Tag: ref parameters

为什么匿名方法中不允许使用out参数?

这不是使用匿名方法的ref或out参数调用方法的欺骗 我想知道为什么在匿名方法中不允许输出参数。 不允许ref参数对我来说更有意义,但out参数不是那么多。 你对此有何看法?

什么时候C#’out’或’ref’参数的值实际返回给调用者?

当我对out或ref参数进行赋值时,是否会立即将值赋给调用者提供的引用,还是在方法返回时分配给引用的out和ref参数值? 如果方法抛出exception,则返回值吗? 例如: int callerOutValue = 1; int callerRefValue = 1; MyMethod(123456, out callerOutValue, ref callerRefValue); bool MyMethod(int inValue, out int outValue, ref int refValue) { outValue = 2; refValue = 2; throw new ArgumentException(); // Is callerOutValue 1 or 2? // Is callerRefValue 1 or 2? }