[Mono-bugs] [Bug 699182] New: Modifications to a Collection via indexer during foreach should throw InvalidOperationException

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Jun 9 19:58:55 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=699182

https://bugzilla.novell.com/show_bug.cgi?id=699182#c0


           Summary: Modifications to a Collection via indexer during
                    foreach should throw InvalidOperationException
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.10.x
          Platform: i686
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: himajin100000 at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows NT 5.1; rv:7.0a1) Gecko/20110609
Firefox/7.0a1

Modifications to a Collection via indexer during foreach should throw
InvalidOperationException.

Insert,Add, Remove etc increments _version, but setting through indexer does
not.
https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Collections.Generic/List.cs
https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Collections.Generic/List.cs#L629


Reproducible: Always

Steps to Reproduce:
1. Run the following Code

// http://ideone.com/A3DbN

using System;
using System.Collections.Generic;

namespace test
{
    public class test
    {
        public static void Main()
        {
            List<int> x = new List<int>();
            x.Add(1);
            x.Add(4);
            x.Add(9);
            foreach(int i in x){
                x[2] = 3;
            }
            foreach(int i in x){
                System.Console.WriteLine(i);
            }            
        }
    }
}
Actual Results:  
1
4
3

Expected Results:  
InvalidOperationException

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list