C# - Does foreach() iterate by reference?

Posted by sharkin on Stack Overflow See other posts from Stack Overflow or by sharkin
Published on 2009-10-08T14:47:29Z Indexed on 2010/06/07 21:02 UTC
Read the original article Hit count: 182

Filed under:
|
|

Consider this:

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

Is 'obj' a reference to the corresponding object within the list so that when I change the property the change will persist in the object instance once constructed somewhere?

© Stack Overflow or respective owner

Related posts about c#

Related posts about foreach