c# - 无法将类型 Void 隐式转换为类型 System.Collections.Generic.IList<T>

标签 c# generics

尝试返回泛型类型时出现标题中描述的错误。 我确定我在做一些愚蠢的事情 - 建议感谢...

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/

相关文章:

c# - JSON 映射到 C# 类

java - 泛型 - 编译器不一致 [jdk 1.8.0_162]

c - 通用 C 函数的字符串比较函数

具有继承和协变的 Java 泛型

Java Generics WildCard - 如何在此处将泛型与 Lambda 一起使用?

c# - 如何在不违反依赖注入(inject)的情况下为单个数据库使用多个上下文

C# Winforms - 设置组合框选择的值

c# - 可移植类库是否适用于 .net 3.5?

c# - 3 窗体 Show 和 ShowDialog 没有按预期工作,BUG?

generics - TypeScript 报告泛型函数中不存在的属性