【问题标题】:I am getting this error while placing data from data table into chart将数据表中的数据放入图表时出现此错误
【发布时间】:2021-01-19 18:11:00
【问题描述】:

cs1503 参数 1 无法从 'system.collections.generic.list >' 转换为 "System.Collections.GenericList

【问题讨论】:

  • 您可能有一个创建匿名类型的 Lambda,而不是一个新的 Coursework.Customer 对象(或返回枚举的对象)。没有代码,很难帮你。
  • 我已经更新了代码
  • 不,你没有。
  • 我可以给你发邮件吗?
  • 您可以简单地edit这个问题并粘贴到代码中

标签: c# winforms


【解决方案1】:

您必须将两个表中的数据映射在一起。例如,您有一个产品表,产品有名称和价格。你想把产品变成汽车桌,汽车有名字和价格。因此,您将产品的名称和价格分配给汽车表的名称和价格。

public class Product
{
  public string ProductName { get; set; }
  public string Price { get; set; }
}
public class Car
{
  public string CarName { get; set; }
  public string Price { get; set; }
}

List<Product> products = new List<Product>()
{
  new Product(){ProductName = "Car1", Price = "1,000,000"},
  new Product(){ProductName = "Car2", Price = "1,000,000"},
  new Product(){ProductName = "Car3", Price = "1,000,000"},
};


List<Car> cars = new List<Car>();
foreach (var item in products)
{
   Car car = new Car();
   car.CarName = item.ProductName;
   car.Price = item.Price;
   cars.Add(car);
}

//You can now use this list...

【讨论】:

    猜你喜欢
    • 2021-12-02
    • 2021-11-03
    • 2022-01-16
    • 2017-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多