gpt4 book ai didi

c# - 尝试使用 WriteLine 在控制台应用程序中显示列表的内容

转载 作者:行者123 更新时间:2023-11-30 15:34:24 25 4
gpt4 key购买 nike

我正在尝试使用 WriteLine 在控制台应用程序中显示列表的内容。我正在使用以下代码:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestCLient.ClientTransactionsServiceReference;

namespace TestCLient
{
class Program
{
static void Main(string[] args)
{
ClientTransactionsServiceClient client = new ClientTransactionsServiceClient();
List<ClientTransactions> ct = client.GetClientTransactions("9999");
ct.ForEach(i => Console.Write(i));
Console.Read();
}
}
}

我得到以下输出:

Output Screenshot

当我调试时,我的列表 (ct) 显示它包含我想要显示的字段。请参见以下屏幕截图:

Debug screenshot

我搜索了许多资源,包括 Stack,以获取我用来编写列表的代码行。我是编程新手,非常感谢您的帮助。

谢谢

最佳答案

Console.Write 正在隐式调用 ToString() 对您尝试在控制台中打印的对象。因为您的类型没有覆盖 ToString(),返回的文本是 Object 类定义的 ToString() 默认实现的结果(所有类型都从中派生)。

不是将 i 作为参数传递给 Console.Write,而是传递 i.NameOfThePropertyYouWantToOutput

关于c# - 尝试使用 WriteLine 在控制台应用程序中显示列表的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16152256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com