diff --git a/mcs/class/System/System.Collections.Generic/LinkedList.cs b/mcs/class/System/System.Collections.Generic/LinkedList.cs index 5fd2c91ddec2e..ef5a7a8b9fe1d 100644 --- a/mcs/class/System/System.Collections.Generic/LinkedList.cs +++ b/mcs/class/System/System.Collections.Generic/LinkedList.cs @@ -182,9 +182,8 @@ public void AddLast (LinkedListNode node) public void Clear () { - count = 0; - first = null; - version++; + while (first != null) + RemoveLast(); } public bool Contains (T value) diff --git a/mcs/class/System/Test/System.Collections.Generic/LinkedListTest.cs b/mcs/class/System/Test/System.Collections.Generic/LinkedListTest.cs index ae7e9f8f52c5c..f5605744bdde2 100644 --- a/mcs/class/System/Test/System.Collections.Generic/LinkedListTest.cs +++ b/mcs/class/System/Test/System.Collections.Generic/LinkedListTest.cs @@ -84,8 +84,13 @@ public void NonCircularNodeTest () [Test] public void ClearTest () { + LinkedListNode node = intlist.First; intlist.Clear (); + Assert.AreEqual (0, intlist.Count); + Assert.AreEqual (2, node.Value); + Assert.IsNull (node.Next); + Assert.IsNull (node.Previous); } [Test]