想要在Output窗口写入文本只需把ConsoleWriteLine() 用
Debug.WriteLine()
Trace.WriteLine()
代替就可以.
但是在Release版本中,Debug()会消失
Debug.WriteLine()
Trace.WriteLine()
代替就可以.
但是在Release版本中,Debug()会消失
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace Csharp
{
class Program
{
static int Maxima(int[] inputArray, out int[] maxValueArray)
{
Console.WriteLine("Start search the maximum value");
int count = 1;
int maxValue = inputArray[0];
maxValueArray = new int[1];
Debug.WriteLine(string.Format(
"Maximum value has initialize to {0}, as index 0", maxValue));
for (int i = 0; i < inputArray.Length; ++i)
{
Debug.WriteLine(string.Format(
"Now looking at element at index {0}", i));
if (maxValue < inputArray[i])
{
maxValue = inputArray[i];
count = 1;
maxValueArray = new int[1];
maxValueArray[0] = i;
Debug.WriteLine(string.Format(
"New maxValue has found: {0}, at index{1}", maxValue, i));
}
else
{
if (maxValue == inputArray[i])
{
count++;
int[] oldMaxValueArray = maxValueArray;
maxValueArray = new int[count];
oldMaxValueArray.CopyTo(maxValueArray, 0);
maxValueArray[count - 1] = i;
Debug.WriteLine(string.Format(
"Duplicate maximum found at element index {0}", i));
}
}
}
Trace.WriteLine(string.Format(
"Maximum value {0} found with {1}", maxValue, count));
Debug.WriteLine(string.Format(
"maxValue found has complete"));
return maxValue;
}
static void Main(string[] args)
{
int[] testArray = { 4, 7, 4, 2, 7, 3, 7, 8, 3, 9, 1, 9 };
int[] maxValueIndices;
int maxValue = Maxima(testArray, out maxValueIndices);
Console.WriteLine("Maximum value {0} has found in element indices", maxValue);
foreach (int index in maxValueIndices)
Console.WriteLine(index); }
}
}