Could someone expand the spectrum of the samples of boxing and performance in .NET?
This sample is clear for me, but are there other cases?
Code optimization flow
BAD CODE
void CountVer1(int max)
{
for (int i = 1; i <= max; i++)
{
Console.WriteLine("{0} out of {1}",
i, max);
}
}
GOOD CODE
void CountVer2(int max)
{
object maxObj = max;
for (int i = 1; i <= max; i++)
{
Console.WriteLine("{0} out of {1}",
i, maxObj);
}
}
IDEAL CODE
void CountVer3(int max)
{
for (int i = 1; i <= max; i++)
{
Console.WriteLine("{0} out of {1}",
i.ToString(), max.ToString());
}
}