C#找不到类型或命名空间名称"List".但我正在导入System.Collections.Generic;

Cal*_*ebB 21 c# mono list monodevelop

我有一个错误

找不到类型或命名空间名称"List".您是否缺少using指令或程序集引用?

示例代码:

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();
}
Run Code Online (Sandbox Code Playgroud)

如果重要我会使用单声道.

Chr*_*air 10

问题来自你的实例化new List().这些还需要通用组件:

public static List<string> items = new List<string>();
public static List<double> itemsprice = new List<double>();
public static List<double> qu = new List<double>();
Run Code Online (Sandbox Code Playgroud)

也就是说,没有类型,List但有一个泛型类型List<T>.

List<T>可以在MSDN文档中找到有关实例化通用实用程序的更多信息和示例.

  • 就我而言,我必须添加“using System.Collections.Generic;” (14认同)