使用system.Collections.generic时找不到(C#)类型或命名空间列表

使用system.Collections.generic时找不到(C#)类型或命名空间列表,c#,list,types,namespaces,C#,List,Types,Namespaces,我在C#中创建列表时遇到问题。它表示找不到类型或命名空间“文件”。据我所知,我正在使用System.Collections.Generic并创建“正确”列表 除了列表之外,我基本上什么都没有(之前使用过array,但它不符合要求): 使用系统; 使用System.IO; 使用System.Collections.Generic; 名称空间周3\u Opdracht\u 3 { 班级计划 { public list streamReaderResults=new list(); 私有静态字符串cu

我在C#中创建列表时遇到问题。它表示找不到类型或命名空间“文件”。据我所知,我正在使用System.Collections.Generic并创建“正确”列表

除了列表之外,我基本上什么都没有(之前使用过array,但它不符合要求):

使用系统;
使用System.IO;
使用System.Collections.Generic;
名称空间周3\u Opdracht\u 3
{
班级计划
{
public list streamReaderResults=new list();
私有静态字符串currentFileLine;
静态void Main(字符串[]参数)
{
StreamReader opdrachtDrieFile=新的StreamReader(@“C:\Users\sande\Documents\VisualStudio school\.txt要读取的文件\Opdracht 3 tekst.txt”);
而((currentFileLine=opdrachtDrieFile.ReadLine())!=null)
{
//还没有。
}
Console.ReadKey();
}
}
}
据我所知,您可以通过键入“list[列表名称]=newlist();”来创建一个列表。然而,这不起作用。为什么我会收到此错误消息?

C#是一种区分大小写的语言,因此您需要注意大小写。此外,程序中的
Main
是一种
static
方法,只能访问
static
程序类的成员。因此,您需要将
列表
标记为静态:

namespace Week_3_Opdracht_3
{
    class Program
    {
        public static List<string> streamReaderResults = new List<string>();


        private static string currentFileLine;

        static void Main(string[] args)
        {

            StreamReader opdrachtDrieFile = new StreamReader(@"C:\Users\sande\Documents\VisualStudio school\.txt files to read\Opdracht 3 tekst.txt");

            while ((currentFileLine = opdrachtDrieFile.ReadLine()) != null)
            {
                //nothing yet.
            }
            Console.ReadKey();
        }
    }
}
namespace Week\u 3\u Opdracht\u 3
{
班级计划
{
public static List streamReaderResults=new List();
私有静态字符串currentFileLine;
静态void Main(字符串[]参数)
{
StreamReader opdrachtDrieFile=新的StreamReader(@“C:\Users\sande\Documents\VisualStudio school\.txt要读取的文件\Opdracht 3 tekst.txt”);
而((currentFileLine=opdrachtDrieFile.ReadLine())!=null)
{
//还没有。
}
Console.ReadKey();
}
}
}

您需要将列表设置为静态

public static List<string> streamReaderResults = new List<string>();
public static List streamReaderResults=new List();

欢迎来到SO!拿着书读吧!(注意:您的问题当前的问题是您只是说“这不起作用”)您是否查看了项目引用以查看是否正确找到了程序集?
List
区分大小写,所以它应该是
List
而不是
List
。如果从static
Main
方法访问它,它也需要是静态的。我从来没有注意到List带有大写字母“L”。谢谢:)我对编程很陌生。我的老师告诉我们尽可能使事物保持静止。我很快就会读到的。
public static List<string> streamReaderResults = new List<string>();