string categoryIDList = Convert.ToString(reader["categoryIDList"]);
if (!String.IsNullOrEmpty(categoryIDList))
{
c.CategoryIDList =
new List<int>().AddRange(
categoryIDList
.Split(',')
.Select(s => Convert.ToInt32(s)));
}
Run Code Online (Sandbox Code Playgroud)
该类有一个属性IList CategoryIDList,我试图分配给上面.
错误:
错误1无法将类型'void'隐式转换为'System.Collections.Generic.IList'
不确定是什么问题?
您的问题是泛型List类的AddRange方法被声明为返回void.
更新:编辑修复List<int>与IList<int>问题.
您需要将其更改为:
List<int> foo = new List<int>();
foo.AddRange(
categoryIDList
.Split(',')
.Select(s => Convert.ToInt32(s)));
c.CategoryIDList = foo;
Run Code Online (Sandbox Code Playgroud)