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

怎甘沉沦 提交于 2019-12-17 16:59:36

问题


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.

However, when I change it to list of list, it gives me an error of 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

So, what does it mean and what did I do wrong using it?


回答1:


The List<T> class is a generic type.

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.




回答2:


I guess you wrote something like List<List>> ...
But there is no class named List.. - List has a generic type parameter.
For example - list of lists of integers should be

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

For better understanding of C# generics take a look here.




回答3:


I was able to just use using System.Collections.Generic; to get access to lists.



来源:https://stackoverflow.com/questions/3223102/using-the-generic-type-system-collections-generic-listt-requires-1-type-argu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!