Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法使用集合初始值设定项初始化类型x,因为它未实现';System.Collections.IEnumerable';_C#_Asp.net Mvc_Asp.net Mvc 5 - Fatal编程技术网

C# 无法使用集合初始值设定项初始化类型x,因为它未实现';System.Collections.IEnumerable';

C# 无法使用集合初始值设定项初始化类型x,因为它未实现';System.Collections.IEnumerable';,c#,asp.net-mvc,asp.net-mvc-5,C#,Asp.net Mvc,Asp.net Mvc 5,我正在验证此代码,但它向我发送有关集合初始化的错误 无法使用集合初始值设定项初始化类型x,因为它未实现“System.Collections.IEnumerable” 我正在用MVC5尝试这一点 private readonly List clients = new List() { new Pruebas.Models.Client { Id = 1, Name = "Julio Avellaneda", Email = "julito_gtu@hotmail.com"

我正在验证此代码,但它向我发送有关集合初始化的错误

无法使用集合初始值设定项初始化类型x,因为它未实现“System.Collections.IEnumerable”

我正在用MVC5尝试这一点

private readonly List clients = new List()
   {
        new Pruebas.Models.Client { Id = 1, Name = "Julio Avellaneda", Email = "julito_gtu@hotmail.com" },
        new Pruebas.Models.Client { Id = 2, Name = "Juan Torres", Email = "jtorres@hotmail.com" },
        new Pruebas.Models.Client { Id = 3, Name = "Oscar Camacho", Email = "oscar@hotmail.com" },
        new Pruebas.Models.Client { Id = 4, Name = "Gina Urrego", Email = "ginna@hotmail.com" },
        new Pruebas.Models.Client { Id = 5, Name = "Nathalia Ramirez", Email = "natha@hotmail.com" },
        new Pruebas.Models.Client { Id = 6, Name = "Raul Rodriguez", Email = "rodriguez.raul@hotmail.com" },
        new Pruebas.Models.Client { Id = 7, Name = "Johana Espitia", Email = "johana_espitia@hotmail.com" }

    };
我的班级名单

class List
{

}

我认为您需要使用
System.Collections.Generic
中的
List
,而不是创建自己的List类。您的list类只是一个空类。为了实现您正在做的事情,请删除list类,导入命名空间
System.Collections.Generic
并使用
list

这是您的代码使用列表

删除你的列表类

然后像这样导入System.Collections.Generic命名空间

Using System.Collections.Generic;
然后使用下面的代码

private readonly List<Pruebas.Models.Client> clients = new List<Pruebas.Models.Client>()
{
        new Pruebas.Models.Client { Id = 1, Name = "Julio Avellaneda", Email = "julito_gtu@hotmail.com" },
        new Pruebas.Models.Client { Id = 2, Name = "Juan Torres", Email = "jtorres@hotmail.com" },
        new Pruebas.Models.Client { Id = 3, Name = "Oscar Camacho", Email = "oscar@hotmail.com" },
        new Pruebas.Models.Client { Id = 4, Name = "Gina Urrego", Email = "ginna@hotmail.com" },
        new Pruebas.Models.Client { Id = 5, Name = "Nathalia Ramirez", Email = "natha@hotmail.com" },
        new Pruebas.Models.Client { Id = 6, Name = "Raul Rodriguez", Email = "rodriguez.raul@hotmail.com" },
        new Pruebas.Models.Client { Id = 7, Name = "Johana Espitia", Email = "johana_espitia@hotmail.com" }

};
private readonly List clients=new List()
{
新的Pruebas.Models.Client{Id=1,Name=“Julio Avellanda”,Email=“julito_gtu@hotmail.com" },
新的Pruebas.Models.Client{Id=2,Name=“Juan Torres”,Email=”jtorres@hotmail.com" },
新的Pruebas.Models.Client{Id=3,Name=“Oscar Camacho”,Email=”oscar@hotmail.com" },
新的Pruebas.Models.Client{Id=4,Name=“Gina Urrego”,Email=”ginna@hotmail.com" },
新的Pruebas.Models.Client{Id=5,Name=“Nathalia Ramirez”,电子邮件=”natha@hotmail.com" },
新的Pruebas.Models.Client{Id=6,Name=“Raul Rodriguez”,Email=“Rodriguez。raul@hotmail.com" },
新的Pruebas.Models.Client{Id=7,Name=“Johana Espitia”,Email=“Johana_espitia@hotmail.com" }
};

为什么您有自己的自定义
列表
类?为什么不使用内置类呢?这个错误似乎很合适。您的“List”类不是IEnumerable。List似乎只是一个名为List的空类。也许您想做的是使用List,例如:private readonly List clients=new List(),这些看起来像真正的电子邮件地址。你确定他们应该在那里吗?