Change value using Extension Method in C# (as allowed in VB.NET)
问题 I am trying to make something like string s = "Hello"; s.Clear(); And I created the extension method like this: public static void Clear(this string s) { s = string.Empty; } But, when I see the value, it does not change: I can't use ref or out because these can't be used with the keyword this . Any ideas? 回答1: This is not possible. From the documentation: Strings are immutable--the contents of a string object cannot be changed after the object is created, although the syntax makes it appear