Hi all
I work on applications developed in C#/.NET with Visual Studio and very often Resharper, in the prototypes of my methods, advises me to replace the type of my input parameters with more generic ones. For instance List<> with IEnumerable<> if I only use the list with a foreach in the body of my method. I can understand why it looks smarter to write that but I'm quite concerned with the performance. I fear that the performance of my apps will decrease if I listen to Resharper...
Can someone explain to me precisely (more or less) what's happening behind the scene (ie in the CLR) when I write
public void myMethod(IEnumerable<string> list)
{
foreach (string s in list)
{
Console.WriteLine(s);
}
}
static void Main()
{
List<string> list = new List<string>(new string[] {"a", "b", "c"});
myMethod(list);
}
and what is the difference with
public void myMethod(List<string> list)
{
foreach (string s in list)
{
Console.WriteLine(s);
}
}
static void Main()
{
List<string> list = new List<string>(new string[] {"a", "b", "c"});
myMethod(list);
}