Possible Duplicate:
Is it better to call ToList() or ToArray() in LINQ queries?
Hi,
I have following code
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(开发者_如何学Go);
}
Could any one please tell which one is faster
List<string> wordList1 = wordLookup.ToList();
or
string[] wordList2 = wordLookup.ToArray();
List<T>
uses array internally, so my guess is that they'll be equally fast. However, this just doesn't matter -- use whatever makes your code clearer.
My initial reaction would be to say that ToArray would be faster, but honestly the only way to tell is to time it yourself.
精彩评论