using System.Diagnostics;
string testString = "apple";
Stopwatch stopwatch1 = new Stopwatch();
for (int i = 0; i < iterations; i++)
bool startsWithA1 = testString.StartsWith("a");
Console.WriteLine($"str.StartsWith(\"a\") 执行时间: {stopwatch1.Elapsed.TotalMilliseconds} 毫秒");
Stopwatch stopwatch2 = new Stopwatch();
for (int i = 0; i < iterations; i++)
bool startsWithA2 = testString!=null&&testString.Length>0&&testString[0] == 'a';
Console.WriteLine($"str[0] == 'a' 执行时间: {stopwatch2.Elapsed.TotalMilliseconds} 毫秒");