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;
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
