What is the best rewrite of this method to speed it up?
这种加速方法的最佳重写是什么?
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;
}
6 个解决方案
#1
Maybe I am missing the point completely, but I would spontaneously go for the String.EndsWith
method.
也许我完全忽略了这一点,但我会自发地去寻找String.EndsWith方法。
#2
You may want to drop the method rather than rewrite it...
您可能希望删除该方法而不是重写它...
public static bool EndsWith(string line, string term)
{
return line.EndsWith(term);
}
#3
Could you use the .NET builtin in string.Endwith() method?
你能在string.Endwith()方法中使用.NET内置吗?
#4
Can't you just use the standard string.EndsWith() function??
你能不能只使用标准的string.EndsWith()函数?
#5
Is there any reason you aren't using the build in String.EndsWith method? I imagine that will be the fastest solution most of the time.
您是否有任何理由不在String.EndsWith方法中使用构建?我想这将是大多数时候最快的解决方案。
#6
line.EndsWidth(term)
#1
Maybe I am missing the point completely, but I would spontaneously go for the String.EndsWith
method.
也许我完全忽略了这一点,但我会自发地去寻找String.EndsWith方法。
#2
You may want to drop the method rather than rewrite it...
您可能希望删除该方法而不是重写它...
public static bool EndsWith(string line, string term)
{
return line.EndsWith(term);
}
#3
Could you use the .NET builtin in string.Endwith() method?
你能在string.Endwith()方法中使用.NET内置吗?
#4
Can't you just use the standard string.EndsWith() function??
你能不能只使用标准的string.EndsWith()函数?
#5
Is there any reason you aren't using the build in String.EndsWith method? I imagine that will be the fastest solution most of the time.
您是否有任何理由不在String.EndsWith方法中使用构建?我想这将是大多数时候最快的解决方案。
#6
line.EndsWidth(term)