这种加快速度的方法有哪些最好的改写?
public static bool EndsWith(string line, string term)
{
bool rb = false;
int lengthOfTerm = term.Length;
string endOfString = StringHelpers.RightString(line, lengthOfTerm);
if (StringHelpers.AreEqual(term, endOfString))
{
return true;
}
else
{
rb = false;
}
if (line == term)
{
rb = true;
}
return rb;
}
答案 0 :(得分:24)
也许我完全忽略了这一点,但我会自发地采用String.EndsWith
方法。
答案 1 :(得分:6)
您可能希望删除该方法而不是重写它...
public static bool EndsWith(string line, string term)
{
return line.EndsWith(term);
}
答案 2 :(得分:4)
你能使用string.Endswith()方法中内置的.NET吗?
答案 3 :(得分:3)
你能不能只使用标准的string.EndsWith()函数??
答案 4 :(得分:3)
你有没有理由不在String.EndsWith方法中使用构建?我想这将是大多数时候最快的解决方案。
答案 5 :(得分:3)
line.EndsWidth(术语)