输出调试信息

3 本我 15小时前 61次点击

示例:

using System;

using static System.Console;

using System.Diagnostics;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace 录音1

{

class Program

{

//定义函数:最大值

static int 最大值(int[] 测试数组, out int[] 索引)

{

Debug.WriteLine("现在开始最大值搜索");

int 最大值 = 测试数组[0];

索引 = new int[1];

索引[0] = 0;

int 计算 = 1;

Debug.WriteLine(string.Format($"在元素索引0处最大值{最大值}"));

for (int i = 1; i < 测试数组.Length; i++)

{

Debug.WriteLine(string.Format($"现在查看索引{i}处的元素"));

if (测试数组[i] > 最大值)

{

最大值 = 测试数组[i];

计算 = 1;

索引 = new int[1];

索引[0] = i;

Debug.WriteLine(string.Format($"找到最大值{最大值}位于元素索引{i}处"));

}

else

{

if (测试数组[i] == 最大值)

{

计算++;

int[] 旧索引 = 索引;

旧索引.CopyTo(索引,0);

索引 = new int[计算];

索引[计算 - 1] = i;

Debug.WriteLine(string.Format($"在元素索引{i}处找到重复的最大值"));

}

}

}

Trace.WriteLine(string.Format($"找到最大值{最大值}重复{计算}次"));

Debug.WriteLine("完成最大值搜索");

return 最大值;

}

static void Main(string[] args)

{

int[] 测试数组 = { 1,2,3,4,4,5,5};

int[] 测试索引;

WriteLine($"最大值{最大值(测试数组,out 测试索引)}");

foreach (int 列出 in 测试索引)

{

WriteLine(列出);

}

ReadKey();

}

}

}

f5后不要退出运行,alt+tab切到编辑器界面,alt找视图,下光标找输出。


共 1 条评论
五阶强者 14小时前
0 
哇,看来你是系统的学习过了,佩服佩服
添加一条新评论

登录后可以发表评论 去登录