为什么不StringBuilder的有IndexOf方法?方法、StringBuilder、IndexOf

2023-09-03 01:22:43 作者:伊人浓妆╮依然憔悴

我知道我可以调用toString()。的IndexOf(...),但我不希望创建一个额外的字符串。我知道我可以手工编写一个搜索程序。我不知道为什么这样一个例程不已经在框架存在。

I understand that I can call ToString().IndexOf(...), but I don't want to create an extra string. I understand that I can write a search routine manually. I just wonder why such a routine doesn't already exist in the framework.

推荐答案

不幸的是,许多实施了字符串的方法可能已实施的StringBuilder但是却没有这样做。考虑使用扩展方法来添加你所关心的事情。

Unfortunately, many of the methods implemented for String could have been implemented for StringBuilder but that was not done. Consider using extension methods to add what you care about.