List错误,显示“使用泛型类型“System.Collections.Generic.List”;需要 1 个类型参数”

发布于 2024-11-04 08:27:09 字数 2512 浏览 0 评论 0原文

从事购物部分的工作正在发生奇怪的事情。当我去填充我的 lixt 时,我收到错误:

使用泛型类型 '系统.集合.通用.列表' 需要 1 个类型参数

我已经在其他几个类上执行了此操作,但没有一个给出此错误。这是导致错误的类:

StoreItem.cs

public class StoreItemViewModel
{
    public StoreItemViewModel()
    {
        this.StoreItems = GetStoreItemList(null);
    }

    private SelectList GetStoreItemList(string selectedValue)
    {
        List<StoreItems> list = new List<StoreItems>(); 
        IRepository<GodsCreationTaxidermy.Data.StoreItem> storeItems = ObjectFactory.GetInstance<IRepository<StoreItem>>();

        foreach (StoreItem item in storeItems.GetAll())
        {
            List.Add(new StoreItems <= error on this line
            {
                Key = item.Key,
                CategoryKey = item.CategoryKey,
                ItemName = item.ItemName,
                ItemDescription = item.ItemDescription,
                ItemPriced = item.ItemPrice,
                DatePosted = item.DatePosted,
            });
        }

        return new SelectList(list, "StoreItemID", "StoreItemName", selectedValue);
    }

    [UIHint("StoreItems")]
    public SelectList StoreItems { get; private set; }

    [Required(ErrorMessage = "Store Item is required")]
    public string StoreItem { get; set; }
}

我可以向其他类展示执行此操作的其他类(也许这里可以使用一组新的眼睛),这是其中之一:

AnimalList.cs< /strong>

public class AnimalsList
{
    public AnimalsList()
    {
        this.Animals = GetanimalList(null); 
    }

    private SelectList GetanimalList(string selectedValue)
    {

        List<Animal> list = new List<Animal>();
        IRepository<AnimalList> animals = ObjectFactory.GetInstance<IRepository<AnimalList>>();

        foreach (AnimalList animal in animals.GetAll())
        {
            list.Add(new Animal
            {
                AnimalId = animal.animal_id,
                AnimalName = animal.animal_name,
                IsBird = Convert.ToBoolean(animal.is_bird),
                MountType = animal.mount_type
            });
        }

        return new SelectList(list, "AnimalId", "AnimalName", selectedValue);
    }

    [UIHint("Animal")]
    public SelectList Animals { get; private set; }

    [Required(ErrorMessage = "Animal is required")]
    public string Animal { get; set; }
}

有人可以告诉我我在这里做错了什么吗?过去几天我看到了很多非常晦涩的错误(大多数我解决了),但其他错误我不得不寻求帮助。如果您需要更多代码,请告诉我:)

Working on the shopping part of thisnd smeting strange is happening. When I go to populate my lixt I get the error:

Using the generic type
'System.Collections.Generic.List'
requires 1 type arguments

I have done this on several other classes but none give this error. Here's the class causing the error:

StoreItem.cs

public class StoreItemViewModel
{
    public StoreItemViewModel()
    {
        this.StoreItems = GetStoreItemList(null);
    }

    private SelectList GetStoreItemList(string selectedValue)
    {
        List<StoreItems> list = new List<StoreItems>(); 
        IRepository<GodsCreationTaxidermy.Data.StoreItem> storeItems = ObjectFactory.GetInstance<IRepository<StoreItem>>();

        foreach (StoreItem item in storeItems.GetAll())
        {
            List.Add(new StoreItems <= error on this line
            {
                Key = item.Key,
                CategoryKey = item.CategoryKey,
                ItemName = item.ItemName,
                ItemDescription = item.ItemDescription,
                ItemPriced = item.ItemPrice,
                DatePosted = item.DatePosted,
            });
        }

        return new SelectList(list, "StoreItemID", "StoreItemName", selectedValue);
    }

    [UIHint("StoreItems")]
    public SelectList StoreItems { get; private set; }

    [Required(ErrorMessage = "Store Item is required")]
    public string StoreItem { get; set; }
}

I can show other classes that do this exact thing (maybe a new set f eyes can here) and here's one of them:

AnimalList.cs

public class AnimalsList
{
    public AnimalsList()
    {
        this.Animals = GetanimalList(null); 
    }

    private SelectList GetanimalList(string selectedValue)
    {

        List<Animal> list = new List<Animal>();
        IRepository<AnimalList> animals = ObjectFactory.GetInstance<IRepository<AnimalList>>();

        foreach (AnimalList animal in animals.GetAll())
        {
            list.Add(new Animal
            {
                AnimalId = animal.animal_id,
                AnimalName = animal.animal_name,
                IsBird = Convert.ToBoolean(animal.is_bird),
                MountType = animal.mount_type
            });
        }

        return new SelectList(list, "AnimalId", "AnimalName", selectedValue);
    }

    [UIHint("Animal")]
    public SelectList Animals { get; private set; }

    [Required(ErrorMessage = "Animal is required")]
    public string Animal { get; set; }
}

Can someone tell me wat I'm doing wrong here. I've seen a lot of very obscure errors the past few days (most I resolved) but others I had to ask for help.If you nee more code then ust let me know :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阳光下慵懒的猫 2024-11-11 08:27:09

列表是大写的,因此您引用的是类而不是实例“列表”。

您应该考虑将变量名称更改为有用的名称,并且不易模糊或不易出错,以便您可以更快地捕获这些变量,或完全阻止它们。

List is capitalized, so you're referencing the Class instead of the instance "list".

You should consider changing the variable name to something useful, and less vague or error prone so you can catch these faster, or prevent them entirely.

玩世 2024-11-11 08:27:09

在代码中您会看到List.Add,这是行不通的。一旦我把它变成小写,一切都很好。

In the code you see List.Add, that's not going to work. Once I made it lower case all is well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文