尝试返回泛型类型时出现标题中描述的错误。 我确定我在做一些愚蠢的事情 - 建议感谢...
public static IList<T> GetGroupById<T>(int groupId)
{
DashboardGroupType type = (DashboardGroupType)groupId;
IList<T> result = null;
var obj = default(T);
switch (type)
{
case DashboardGroupType.Countries:
break;
case DashboardGroupType.Customers:
// this returns a list of typ IEnumerable<Customer>
obj = (T) CustomerRepository.GetAllCustomers();
break;
case DashboardGroupType.Facilities:
// this returns a list of typ IEnumerable<Facility>
obj = (T) FacilityRepository.GetAllFacilities();
break;
case DashboardGroupType.Heiarchy:
break;
case DashboardGroupType.Lines:
break;
case DashboardGroupType.Regions:
// this returns a list of typ IEnumerable<string>
obj = (T) CustomerRepository.GetRegionsHavingCustomers();
break;
case DashboardGroupType.States:
// // this returns a list of typ IEnumerable<Customer>
obj = (T) CustomerRepository.GetStatesHavingCustomers();
break;
case DashboardGroupType.Tanks:
break;
default:
break;
}
result = result.Add(obj); // ERROR IS THROWN HERE
}
最佳答案
result = result.Add(obj);
Add() 不返回任何东西。 删除“结果=”
关于c# - 无法将类型 Void 隐式转换为类型 System.Collections.Generic.IList<T>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4876729/