C# 正在尝试使用WriteLine在控制台应用程序中显示列表的内容
我试图用WriteLine在控制台应用程序中显示列表的内容。我正在使用以下代码:C# 正在尝试使用WriteLine在控制台应用程序中显示列表的内容,c#,wcf,C#,Wcf,我试图用WriteLine在控制台应用程序中显示列表的内容。我正在使用以下代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TestCLient.ClientTransactionsServiceReference; namespace T
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();
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用TestCLient.ClientTransactionsServiceReference;
命名空间测试客户端
{
班级计划
{
静态void Main(字符串[]参数)
{
ClientTransactionServiceClient=新的ClientTransactionServiceClient();
List ct=client.GetClientTransactions(“9999”);
ct.ForEach(i=>Console.Write(i));
Console.Read();
}
}
}
我得到以下输出:
调试时,我的列表(ct)显示它包含我想要显示的字段。请参见以下屏幕截图:
我已经搜索了很多源代码,包括Stack,以获得我用来编写列表的代码行。我是编程新手,非常感谢您的帮助
谢谢因为您正在输出
ClientTransactions的实例
,所以需要指定如何在控制台上呈现信息。您可以输出此实例的一个或多个属性,也可以重写ToString()
方法。控制台。Write
隐式调用您试图在控制台中打印的对象上的ToString()
。由于您的类型不重写ToString()
,因此返回的文本是ToString()
的默认实现的结果,该默认实现由对象
类定义(所有类型都从该类派生)
不要将
i
作为参数传递给控制台。编写passi.nameofPropertyYouwanttoOutput
您可以打印出所需的每个属性。。或者更好的方法是重写ToString()
方法,并在以下代码中调用类似的方法:
ct.ForEach(i=>Console.Write(i.ToString())代码>尝试将对象解析为字符串
如果要在控制台中正确显示对象,则需要显示客户端对象的成员
ct.ForEach(i => Console.Write(i.Name )); // exemple
Console.Read();
您必须编写ClientTransactions的一些属性。不是像我一样的东西你能上传一个更大的截图吗?我们几乎什么也看不见。很可能,您需要编写类似于Console.WriteLine(i.Property1+“”+i.Property2)
的代码来显示实际的contents@JuliánUrbano因此重新调整图像大小以适合线程。右键单击>查看图像|在新选项卡中打开:我想你可以从每个人给你的提示中把问题拼凑起来;)@再见!我以为这只是因为图像没有链接#诺贝