不能隐式转换类型'string'& # 39; int # 39;数组中
本文关键字:int 数组 不能 转换 string 类型 | 更新日期: 2023-09-27 18:15:22
public class Product
{
public string name { get; set; }
public string description { get; set; }
public decimal price { get; set; }
public int [] categories { get; set; }
}
var parentstl = from parentstyle in DBB.vParentStyles
select new
{
parentstyle.name,
parentstyle.description,
parentstyle.price,
Categories = parentstyle.categories.ToArray(),
};
foreach (var pstl in parentstl)
{
request.AddBody(new Product
{
name = pstl.name,
description = pstl.description,
price = (Decimal)pstl.price,
**categories = new int[]{pstl.categories}.ToArray()**
});
}
错误1不能隐式地将类型'string'转换为'int'.我该如何解决这个问题?谢谢。
你可以用Linq,改变这个:
**categories = new int[]{pstl.categories}.ToArray()**
:
categories = pstl.categories.Select(int.Parse).ToArray();