可以PARAMS使用由裁判通过使用功能产量传递变量 [英] Can params be used to pass variables by ref via a function using yield

查看:139
本文介绍了可以PARAMS使用由裁判通过使用功能产量传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有了一个 PARAMS 参数的方法,是否可以通过引用传递和更新每一个收益率被称为时间。

If I have a method that has a params parameter, can it be passed by reference and updated every time a yield is called.

事情是这样的:

public static void GetRowsIter(ref params valuesToUpdate)
{

    foreach(row in rows)
    {
       foreach(param in valuesToUpdate
       {
          GetValueForParam(param)
       }
       yield;
    }
}

是合法的(我远离我的?编译器或我只是尝试一下。)

Is that legal? (I am away from my compiler or I would just try it out.)

推荐答案

没有 PARAMS 只是创建包含要传递的参数数组。此数组,所有其他人一样,仅仅是变量的集合,这是不可能的申报 REF 变量或数组类型,因为这只是实际明确的参数,可以为传递REF 退出

No. params just creates an array that contains the parameters being passed. This array, like all others, is just a collection of variables, and it's not possible to declare a ref variable or array type. Because of this only actual explicit parameters can be passed as ref or out.

话虽这么说,如果该类型是引用类型,那么它会表现出引用类型的语义和往常一样,这意味着所作的任何更改的对象的将体现在所有代码有权访问该引用。只有的分配到实际的变量的就无法体现。

That being said, if the type is a reference type then it will exhibit reference type semantics as usual, meaning that any changes made to the object will be reflected in all code that has access to that reference. Only assignments to the actual variable would not be reflected.

不过,我不能确定到底是什么你的代码是打算这样做。在收益语句要么已被随后收益语句和值或由突破语句,该语句结束迭代器。

However, I'm not certain exactly what your code is intended to do. The yield statement either has to be followed by the return statement and a value or by the break statement, which ends the iterator.

这篇关于可以PARAMS使用由裁判通过使用功能产量传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆