可能重複:
Is it better to call ToList() or ToArray() in LINQ queries?哪一個是更快的字符串[]或列表<string>
嗨,
我有下面的代碼
static void Main(string[] args)
{
const string FileName = @"c:\words";
HashSet<string> wordLookup = new HashSet<string>(File.ReadAllLines(FileName), StringComparer.InvariantCultureIgnoreCase);
List<string> wordList1 = wordLookup.ToList();
string[] wordList2 = wordLookup.ToArray();
}
可以在任何一個告訴哪一個是更快
List<string> wordList1 = wordLookup.ToList();
或
string[] wordList2 = wordLookup.ToArray();
而且您並不在意如何快速且簡單地查找項目,複製/克隆,插入/刪除項目等? – 2011-04-18 15:56:05
編寫一個循環並使用StopWatch類。 – 2011-04-18 15:56:06
我所能做的只是感嘆。這兩行代碼的工作速度都比我感嘆的要快。 – BoltClock 2011-04-18 15:56:09