如何在aspx中的for循环中打印东西Console.WrileLine()

时间:2020-06-21 18:19:24

标签: c#

这是我的代码,我想在aspx页面上的for循环中打印这些数组

                  for (int i = 0; i < notes.Count; i++)
                    {
                        if (noteCounter[i] != 0)
                        {
                              Console.WriteLine(notes[i].Col2 + " : "
                                + noteCounter[i]);

                        }

                    }

它在控制台应用程序中运行良好,我只是将其更改为Web应用程序Web窗体,现在我想在屏幕上打印它,而无需html和css任何

2 个答案:

答案 0 :(得分:1)

第一个解决方案:

您可以使用Log.Write()代替Console.Write(),然后在 Output 窗口中检查日志;当然,您应该在调试模式下运行应用。

首次导入System.Diagnostics

using System.Diagnostics;
// skip
for (int i = 0; i < notes.Count; i++)
{
         if (noteCounter[i] != 0)
         {
               Debug.WriteLine(notes[i].Col2 + " : "
                                + noteCounter[i]);

         }

}

Log 第二个解决方案

您可以记录所有内容并将其保存在单独的文件中,然后在需要时进行检查...无需导入任何内容,只需编写此方法:

public void Logger(string lines)
{
  //Write the string to a file.append mode is enabled so that the log
  //lines get appended to  test.txt than wiping content and writing the log

  using(System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\path\\to\\log\\file.txt", true))
  {
    file.WriteLine(lines);
  }
}

第三种解决方案

登录.NET Core和ASP.NET Core
NET Core支持与各种内置和第三方日志记录提供程序一起使用的日志记录API。本文展示了如何通过内置提供程序使用日志记录API。

本文显示的大多数代码示例均来自ASP.NET Core应用。这些代码段的特定于日志记录的部分适用于使用通用主机的任何.NET Core应用程序。 ASP.NET Core Web应用程序模板使用通用主机。
Read the full article at Microsoft

答案 1 :(得分:0)

将Console.WriteLine更改为document.write