我在将产品对象转换为csv字符串时遇到问题。

var data = ProductPresenter.ExportAllProducts();
string csv = String.Join(",", data.Select(x => x.ToString()).ToArray());


这将产生以下输出:

BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts,BLL.Views.ExportAllProducts


预期输出如下:

Small Hat, 12.10, true
Medium Hat, 13.50, true
Large Hat, 15.00, false
...


我缺少什么转换来从对象的每个项目中获取值?

最佳答案

您的数据变量不是字符串列表,请向该类添加.ToString()方法或创建字符串列表并使用它。

08-25 08:00