C# The type or namespace name `List' could not be found. But I'm importing System.Collections.Generic;

大城市里の小女人 提交于 2020-05-07 21:16:08

问题


I'm having an error

The type or namespace name `List' could not be found. Are you missing a using directive or an assembly reference?

Sample code:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class city1 : MonoBehaviour 
{  
   public static List<string> items = new List ();
   public static List<double> itemsprice = new List();
   public static List<double> qu = new List();
}

I'm using mono if it matters.


回答1:


The issue comes from your instantiation of new List(). These also need the generic component:

public static List<string> items = new List<string>();
public static List<double> itemsprice = new List<double>();
public static List<double> qu = new List<double>();

That is, there is no type List but there is a generic type List<T>.

More information and examples of instantiating the generic List<T> can be found in the MSDN documentation.




回答2:


Replace your code by this:

public static List<string> items = new List<string>();
public static List<double> itemsprice = new List<double>();
public static List<double> qu = new List<double>();



回答3:


Try this:

public static List<string[]> items = new List<string>();

Add brackets after string



来源:https://stackoverflow.com/questions/31733962/c-sharp-the-type-or-namespace-name-list-could-not-be-found-but-im-importing

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