[英]Can't make any list in C#
I can't figure out what is wrong. 我不知道怎么了。 I run this code in Visual Studio in a C# .Net Console Project. 我在C#.Net控制台项目的Visual Studio中运行此代码。 Trying to make a simple list. 试图做一个简单的清单。 I am using lists in more complicated code, but it is not working and now I can't get lists of any kind to run. 我在更复杂的代码中使用列表,但是它不起作用,现在我无法运行任何类型的列表。
I get the error message on the line List<string> Mylist = new List<string>();
我在List<string> Mylist = new List<string>();
行上收到错误消息List<string> Mylist = new List<string>();
The type or namespace 'List<>' could not be found (are you missing a using directive or an assembly reference?). 找不到类型或名称空间“ List <>”(您是否缺少using指令或程序集引用?)。
namespace Lists
{
class Program
{
static void Main()
{
List<string> Mylist = new List<string>();
Mylist.Add("a");
Mylist.Add("b");
Mylist.Add("c");
}
}
}
Include the proper namespace to access the types in it. 包括适当的名称空间以访问其中的类型。 List<T>
is contained in the System.Collections.Generics
namespace so you need to add the following line on top of your program: List<T>
包含在System.Collections.Generics
命名空间中,因此您需要在程序顶部添加以下行:
using System.Collections.Generic;
If you don't know which namespace is missing simply press CTRL + . 如果您不知道缺少哪个名称空间,请按CTRL + 。 on the highlighted line and Visual Studio will add it automatically. 在突出显示的行上,Visual Studio将自动添加它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.