开发者

Which one is faster string[] or List<string> [duplicate]

This question already has answers here: Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜