【发布时间】:2022-04-05 22:24:50
【问题描述】:
我有一个返回类别的递归方法,并检查其子类别。
这是我的代码:
public List<Category> GetAllChildCats(int categoryid)
{
List<Category> list = new List<Category>();
Category c = Get(categoryid);
foreach(Category cat in c.ChildCategories)
{
list.Add(GetAllChildCats(cat.CategoryID));
}
}
这失败了,因为对list.Add() 的调用需要一个Category 对象,但GetAllChildCats() 返回List<Category>
我应该如何解决这个问题?
【问题讨论】: