I need to iterate and count. What is fastest or preferred: ToArray() or ToList()? [duplicate]
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Is it better to call ToList() or ToArray() in LINQ queries? I have code like this: void Foobar(string[] arr, Dictionary<string, string[]>) { var t = arr.Intersect(dic.Keys).ToList(); // .or ToArray() ? foreach(var item in t) { .. } var j = t.Count; // also I need this } which method is preferred? I could go without any but I need to know the size and I don't want to call Enumerable.Count<T>() - it seems do do