Răsfoiți Sursa

Fixed StringBuilder.Clear() to properly clear the cached string.

Paolo Molaro 14 ani în urmă
părinte
comite
8397d2885e

+ 1 - 1
mcs/class/corlib/System.Text/StringBuilder.cs

@@ -506,7 +506,7 @@ namespace System.Text {
 #if NET_4_0 || MOONLIGHT || MOBILE
 		public StringBuilder Clear ()
 		{
-			_length = 0;
+			Length = 0;
 			return this;
 		}
 #endif

+ 12 - 0
mcs/class/corlib/Test/System.Text/StringBuilderTest.cs

@@ -533,6 +533,18 @@ namespace MonoTests.System.Text {
 		Assert.AreEqual (8, sb.Length, "#3");
 		Assert.AreEqual ("Text\0\0\0\0", sb.ToString (), "#4");
 	}
+
+
+#if NET_4_0 || MOONLIGHT || MOBILE
+	[Test]
+	public void ClearMethod () {
+		StringBuilder sb = new StringBuilder ("Text");
+		sb.Clear ();
+		Assert.AreEqual (0, sb.Length, "#1");
+		Assert.AreEqual (String.Empty, sb.ToString (), "#2");
+	}
+#endif
+
 }
 
 }