[Mono-bugs] [Bug 77277][Cri] New - List<T>.Contains does not do the right thing in Mono

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Jan 16 16:05:07 EST 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by psingh at fnfr.com.

http://bugzilla.ximian.com/show_bug.cgi?id=77277

--- shadow/77277	2006-01-16 16:05:07.000000000 -0500
+++ shadow/77277.tmp.13847	2006-01-16 16:05:07.000000000 -0500
@@ -0,0 +1,100 @@
+Bug#: 77277
+Product: Mono: Class Libraries
+Version: 1.1
+OS: RHEL 2.1
+OS Details: Red Hat Enterprise Linux and Fedora
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Critical
+Component: System
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: psingh at fnfr.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: List<T>.Contains does not do the right thing in Mono
+
+The bug is in Mono 1.1.13 on RedHatEnterprise 3.2 and Fedora
+
+On Windows .Net runtime 2.0, List<T>.Contains returns true even if the
+object passed to it is a different instance than one in the list if T is
+IEquatable and the objects are equal if IEquatable interface is checked on
+the objects. But on Linux, mono does not.
+
+Enclosed is the source code example with a makefile which illustrates this.
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace ListContainsBug
+{
+    // On Windows .Net framework 2.0 the output is:    True, False, True, True
+    // On Linux, Mono 1.1.13 the output is: True, False, True, False
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            List<MyType> myList = new List<MyType>();
+            MyType item1 = new MyType("a");
+            MyType item2 = new MyType("b");
+            myList.Add(item1);
+            myList.Add(item2);
+
+            Console.WriteLine("Does it contain item1: " +
+myList.Contains(item1));
+            Console.WriteLine("Does it contain new MyType containing string
+a: " + myList.Contains(new MyType("a")));
+
+
+            List<MyTypeIEquatable> myEqList = new List<MyTypeIEquatable>();
+            MyTypeIEquatable itemX = new MyTypeIEquatable("a");
+            MyTypeIEquatable itemY = new MyTypeIEquatable("b");
+            myEqList.Add(itemX);
+            myEqList.Add(itemY);
+
+            Console.WriteLine("Does IEquatable list contain itemX: " +
+myEqList.Contains(itemX));
+            Console.WriteLine("Does IEquatable list contain new
+MyTypeIEquatable containing string a: " + myEqList.Contains(new
+MyTypeIEquatable("a")));
+
+
+        }
+    }
+
+
+    public class MyType
+    {
+        string _foo = "";
+        public MyType(string val)
+        {
+            _foo = val;
+        }
+    }
+
+    public class MyTypeIEquatable : IEquatable<MyTypeIEquatable>
+    {
+        string _bar = "";
+        public MyTypeIEquatable(string val)
+        {
+            _bar = val;
+        }
+
+        public string Value
+        {
+            get { return _bar; }
+        }
+
+
+        public bool Equals(MyTypeIEquatable other)
+        {
+            return this.Value == other.Value;
+        }
+
+    }
+
+
+}


More information about the mono-bugs mailing list