首页 > 解决方案 > 如何在控制台中查看列表的内容?

问题描述

我有这个变量:

public static List<Phrase> viewablePhrases;

我想看到控制台中记录的内容是这样的:

Console.WriteLine(App.viewablePhrases) 

但这并没有向我显示内容。

有没有办法可以在我的控制台中查看内容?

标签: c#

解决方案


您正在尝试显示列表,而不是您添加到列表中的对象的值:

Phrase您应该输出包含您的对象的字符串值:

public static List<Phrase> viewablePhrases
{
   new Phrase(/* your constructor */)
   // other your Phrase objects
};
for(int i = 0; i < viewablePhrases.Count; i++)
{
    Console.WriteLine(viewablePhrases[i].Value); // or other property instad of "Value"
}

推荐阅读