简体   繁体   中英

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. 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>();

The type or namespace 'List<>' could not be found (are you missing a using directive or an assembly reference?).

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:

using System.Collections.Generic;

If you don't know which namespace is missing simply press CTRL + . on the highlighted line and Visual Studio will add it automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM