In the code on page 159 the string.Format method is used within several Debug.WriteLine statements within the function Maxima. I removed two of them and the program ran exactly the same! Below I put in boldface the two lines of code I changed.
Code:
static int Maxima (int[] integers, out int[] indices)
{
Debug.WriteLine("Maximum value search started.");
indices = new int[1];
int maxVal = integers[0];
indices[0] = 0;
int count = 1;
Debug.WriteLine(string.Format("Maximum value initialized to {0}, at element index 0.",
maxVal));
for (int i = 1; i < integers.Length; i++ )
{
Debug.WriteLine(string.Format("Now looking at element at index {0}.",i));
if(integers[i] > maxVal)
{
maxVal = integers[i];
count = 1;
indices = new int [1];
indices[0] = i;
Debug.WriteLine(
"New maximum found. New value is {0}, at element index {1}.",maxVal, i);
}
else
{
if (integers[i] == maxVal)
{
count++;
int[] oldIndices = indices;
indices = new int[count];
oldIndices.CopyTo(indices, 0);
indices[count-1] = i;
Debug.WriteLine(
"Duplicate maximum found at element index {0}.", i); }
}
}
Trace.WriteLine(string.Format(
"Maximum value {0} found with {1} occurences.", maxVal, count));
Debug.WriteLine("Maximum value search completed.");
return maxVal;
}
}
}