Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #161 from LogosBible/master

Fix bug #311: On LinkedList.Clear, detach each node instead of dropping them en masse.
  • Loading branch information...
commit d23d8aa18ae871a301b5b98b36e942005a3ec69f 2 parents 1fe0e5f + e787a12
Alan McGovern authored August 18, 2011
5  mcs/class/System/System.Collections.Generic/LinkedList.cs
@@ -182,9 +182,8 @@ public void AddLast (LinkedListNode <T> node)
182 182
 		
183 183
 		public void Clear ()
184 184
 		{
185  
-			count = 0;
186  
-			first = null;
187  
-			version++;
  185
+			while (first != null)
  186
+				RemoveLast();
188 187
 		}
189 188
 		
190 189
 		public bool Contains (T value)
5  mcs/class/System/Test/System.Collections.Generic/LinkedListTest.cs
@@ -84,8 +84,13 @@ public void NonCircularNodeTest ()
84 84
 		[Test]
85 85
 		public void ClearTest ()
86 86
 		{
  87
+			LinkedListNode <int> node = intlist.First;
87 88
 			intlist.Clear ();
  89
+
88 90
 			Assert.AreEqual (0, intlist.Count);
  91
+			Assert.AreEqual (2, node.Value);
  92
+			Assert.IsNull (node.Next);
  93
+			Assert.IsNull (node.Previous);
89 94
 		}
90 95
 
91 96
 		[Test]

0 notes on commit d23d8aa

Please sign in to comment.
Something went wrong with that request. Please try again.