简体   繁体   English

使用泛型类型'System.Collections.Generic.List <T>'需要1个类型参数

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

What does it mean? 这是什么意思? I used a list of list in ASP.NET MVC and sent them through ViewData of ActionResuls to retrieve it in views. 我在ASP.NET MVC中使用了一个列表列表,并通过ActionResuls ViewData发送它们以在视图中检索它。

However, when I change it to list of list, it gives me an error of HttpWebException . 但是,当我将其更改为列表列表时,它会给我一个HttpWebException错误。 When I check it inside the immediate window, it tells me that the error is: 当我在即时窗口内检查它时,它告诉我错误是:

Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments 使用泛型类型'System.Collections.Generic.List <T>'需要1个类型参数

So, what does it mean and what did I do wrong using it? 那么,它是什么意思,我用它做错了什么?

The List<T> class is a generic type. List<T>类是泛型类型。

In order to use it, you need to provide a type argument. 要使用它,您需要提供一个类型参数。

For example, if you want to have a list of integers, you need to declare it as List<int> , not List . 例如,如果要获得整数列表,则需要将其声明为List<int> ,而不是List

I guess you wrote something like List<List>> ... 我猜你写了类似List<List>> ...东西List<List>> ...
But there is no class named List.. - List has a generic type parameter. 但是没有名为List的类。 - List有一个泛型类型参数。
For example - list of lists of integers should be 例如 - 整数列表应该是

List<List<int>> listOfLists = .....

For better understanding of C# generics take a look here . 为了更好地理解C#泛型,请看这里

I was able to just use using System.Collections.Generic; 我只能使用using System.Collections.Generic; to get access to lists. 访问列表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Collections.Generic.List <T> 需要&#39;1&#39;类型参数 - System.Collections.Generic.List<T> requires '1' type arguments 使用通用类型System.Collections.Generic.List <T> 需要1个类型参数 - Using the generic type System.Collections.Generic.List<T> requires 1 type arguments 使用泛型类型'System.Collections.Generic.List <T>'需要'1'类型参数 - Using the generic type 'System.Collections.Generic.List<T>' requires '1' type arguments 使用通用类型&#39;System.Collections.Generic.List <T> &#39;在IRepository中需要1个类型参数 - Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments in IRepository 使用泛型类型&#39;System.Collections.Generic.List <T> &#39;需要1个类型的参数 - Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments 错误使用泛型类型&#39;System.Collections.Generic.List&#39;需要&#39;1&#39;类型参数 - Error Using the generic type 'System.Collections.Generic.List' requires '1' type arguments 使用通用类型&#39;System.Collections.Generic.List&#39;需要&#39;1&#39;类型参数 - Using the generic type 'System.Collections.Generic.List' requires '1' type argument(s) 字典需要System.Collections.Generic.List类型的模型项 - Dictionary requires a model item of type System.Collections.Generic.List 键入“对象{System.Collections.Generic.List <T> }“ VS” System.Collections.Generic.List <T> ” - Type “object {System.Collections.Generic.List<T>}” VS “System.Collections.Generic.List<T>” 无法隐式转换类型&#39;System.Collections.Generic.list <fooClass> &#39;到&#39;System.Collections.Generic.List <T> - Cannot Implicitly convert type 'System.Collections.Generic.list<fooClass>' to 'System.Collections.Generic.List<T>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM