faster way between to ways of iterating through all the elements of a collection in C#

Viewed 906

The language I use is C#.

Let we have a List of objects of type T,

List<T> collection = new List<T>{.....};

Say that we want to go over each item of collection. That can be done in many ways. Among of them, are the following two:

foreach(var item in collection)
{
   // code goes here
}

and

foreach(T item in collection)
{
    // code goes here
}

Does the second way be better than the first or not and why?

Thanks in advance for your answers.

5 Answers
Related