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;
基础教程推荐
- 将数据集转换为列表 2022-01-01
- 如果条件可以为空 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
