.NET Framework中的错误String.Remove(char)方法?

Rob*_*cks -2 .net c# string overloading

("hello").Remove('e');
Run Code Online (Sandbox Code Playgroud)

所以String.Remove有很多重载,其中之一是:String.Remove(int startIndex)

不知怎的,我写的字符'e'被转换为a,int并且调用了WRONG重载函数.这是完全出乎意料的事情.我是否只需要忍受这个或者是否有可能提交错误,以便在下一版本的(神圣).NET框架中得到纠正?

RB.*_*RB. 8

String.Remove正好有2个重载,两个都int作为第一个参数.

我相信你正在寻找String.Replace,就像在

string newString = "hello".Replace("e", string.Empty);
Run Code Online (Sandbox Code Playgroud)


Ada*_*rth 5

没有Remove方法需要char......

http://msdn.microsoft.com/en-us/library/143t8z3d.aspx

但是,char可以隐式地转换为a int,所以在你的情况下它是.但它实际上不会删除字母e,而是删除索引处的字符(int)'e'(在您的情况下,它将在运行时超出范围).

如果你想"删除"这封信e,那么:

var newString = "Hello".Replace("e", "");
Run Code Online (Sandbox Code Playgroud)

我预测未来可能存在字符串的不变性.祝好运 ;-)