C# 找不到类型或命名空间名称“List".但我正在导入 System.Collections.Generic; [英] C# The type or namespace name `List' could not be found. But I'm importing System.Collections.Generic;

查看:16
本文介绍了C# 找不到类型或命名空间名称“List".但我正在导入 System.Collections.Generic;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了错误

找不到类型或命名空间名称列表".你失踪了吗using 指令还是程序集引用?

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

示例代码:

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.

推荐答案

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

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

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

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

更多信息和实例化通用 List<T> 的示例可以在 MSDN 文档.

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

这篇关于C# 找不到类型或命名空间名称“List".但我正在导入 System.Collections.Generic;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆