使用泛型类型'System.Collections.Generic.List< T>'需要'1'类型参数“错误? [英] Using the generic type 'System.Collections.Generic.List<T>' requires '1' type arguments" error?

查看:384
本文介绍了使用泛型类型'System.Collections.Generic.List< T>'需要'1'类型参数“错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在asp.net Profile上工作,目前我正在尝试使用表格在表单页面中显示的多个属性,但是当我运行应用程序时,它会显示以下错误:

Hello everybody, I am work on the asp.net Profile and currently I am trying to work on the multiple properties to showing in the form page using table's but when I run the application then it shows the this following error:

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





对于这个应用程序,我写了这段代码:





For this application I had wrote this code:

<anonymousIdentification enabled="true"/>
  <profile automaticSaveEnabled="false">

    <properties>
      <add name="Products" allowAnonymous="true" type="System.Collections.Generic.List[BusinessObject.Products]" serializeAs="Xml"/>
      <!--<add name="Id" type="int" allowAnonymous="true"/>
      <add name="Name" type="String" allowAnonymous="true" />
      <add name="ImageUrl" type="String" allowAnonymous="true"/>
      <add name="Price" type="int" allowAnonymous="true"/>
      <add name="Item" type="int" allowAnonymous="true" />-->

    </properties>
 </profile>





看来我在该属性中声明的类型中的问题但是我不知道如何解决它。在这段代码中,BusinessObject是命名空间,Products是类名。所以请帮我解决这个问题并告诉我它适当的解决方案。请帮我。



It seems the problem in the "Type" which I had declare inside the property but I don't get an any idea how to resolve it.Here's in this code the "BusinessObject is the namespace and the "Products" is the class name.So please help me to resolve this problem and tell me its appropriate solution.Help me please.

推荐答案

可能能够指定正确的通用类型名称:

You might be able to get away with specifying the correct generic type name:
System.Collections.Generic.List`1[BusinessObject.Products]



然而,最简单的解决方案ion将使用自定义非泛型集合类:​​


However, the simplest solution would be to use a custom non-generic collection class:

using System;
using System.Collections.Generic;

namespace BusinessObject
{
    public class ProductsCollection : List<Products>
    {
        public ProductsCollection(IEnumerable<Products> collection) : base(collection)
        {
        }
        
        public ProductsCollection(int capacity) : base(capacity)
        {
        }
        
        public ProductsCollection()
        {
        }
    }
}


这篇关于使用泛型类型'System.Collections.Generic.List&lt; T&gt;'需要'1'类型参数“错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆