Does foreach() iterate by reference?

前端 未结 10 1261
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 23:37

Consider this:

List obj_list = get_the_list();
foreach( MyClass obj in obj_list )
{
    obj.property = 42;
}

Is obj

10条回答
  •  生来不讨喜
    2020-12-04 23:51

    Yes, that's also why you cannot alter the enumerable object in the context of the foreach statement.

提交回复
热议问题