Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.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# 没有<;列表如何存在;T>;之后呢?_C#_List_Types - Fatal编程技术网

C# 没有<;列表如何存在;T>;之后呢?

C# 没有<;列表如何存在;T>;之后呢?,c#,list,types,C#,List,Types,我遇到这样的情况,列表在中没有指定类型: 然而,当我在VisualStudio中尝试此操作时,我得到了一个错误。VS不允许我以这种方式声明List的原因是什么 让我告诉你我在哪里看到的: public override IEnumerable SomeMethod() { List someVar= new List(); // more code return someVar; } 另外,

我遇到这样的情况,
列表
中没有指定类型:

然而,当我在VisualStudio中尝试此操作时,我得到了一个错误。VS不允许我以这种方式声明
List
的原因是什么

让我告诉你我在哪里看到的:

public override IEnumerable SomeMethod()
        {
            List someVar= new List();
            // more code
            return someVar;
        }
另外,在联系了项目的所有者之后,Wordpress发现在
List
IEnumerable
之后去掉了标签
,所以它实际上应该是
List
IEnumerable

public重写IEnumerable方法()
{
List someVar=new List();
//更多代码
返回someVar;
}

我不认识它(在
List
到达之前我以为它是
ArrayList
)。无论哪种方式,它都是在实现泛型之前发明的较旧类。我会使用
List

您会收到一个错误,因为.NET Framework中不存在
List
类。如果要使用可容纳任何类型对象的非通用列表,请使用。

没有名为
list
的内置类。有
ArrayList
,但是:单击
List
并按f12。这将显示声明的位置。有两种选择:

  • 在本地项目中声明了一个名为
    List
    的类,该类与
    List
    无关;例如:

    class List { ...} // here we go; a class called List
    
    using List = System.Collections.Hashtable;
    
  • 使用别名(在文件顶部)的
    已被用来冒充
    列表
    作为名称;例如:

    class List { ...} // here we go; a class called List
    
    using List = System.Collections.Hashtable;
    

    使用List=System.Collections.Generic.List;
    

在您的引用中是否有一个类声明为List?@Paddy:没有,没有这样的类。您使用的是.NET的哪个版本?您使用的是什么
?我在基类的重写方法中看到了它。Look:public override IEnumerable SomeMethod(){List produceObjects=new List();//更多代码返回produceObjects;}@Todo:您已经显示了一个代码段,它在哪里声明的?此项目是否包含名为
List
的类?右键单击它并转到定义。我确信这是一个不属于框架的自定义类。按F12键没有任何作用,因为VS无法识别它。@要检查项目引用,可能缺少一个引用assembly@Todo我的意思是在你看到的项目中按F12used@Mark:事实上,我从Wordpress的博客中获取了这段代码,结果Wordpress删除了一个又一个列表,这就是问题所在。。。否则它就是一个普通的通用列表:)
using List = System.Collections.Generic.List<int>;