C# The type or namespace name `List#39; could not be found. But I#39;m importing System.Collections.Generic;(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;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# 找不到类型或命名空间名称“List".但我正在导入 System.Collections.Generic;


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01