链表上的编译器错误 [英] Compiler Error On Linked List
问题描述
我在链表上写了以下代码:
using System; using System.Collections; using System.Collections.Generic; //using System.Collections.ObjectModel; //using System.Text; class MainClass { static void Main() { LinkedList<int> list = new LinkedList<int>(); list.AddFirst(10); list.AddLast(15); list.AddLast(3); list.AddLast(99); list.AddBefore(list.Last, 25); LinkedListNode<int> node = list.First; while (node != null) { Console.WriteLine(node.Value); node = node.Next; } } }
每当我尝试编译它时,都会出现以下错误:
错误1找不到类型或名称空间名称"LinkedList"(您是否缺少using指令或程序集引用?)
错误2找不到类型或名称空间名称"LinkedList"(您是否缺少using指令或程序集引用?)
错误3找不到类型或名称空间名称"LinkedListNode"(您是否缺少using指令或程序集引用?)
注意:我正在使用Microsoft Visual C#2008 Express Edition.
检查您的引用.查看是否缺少对System的引用.
(在解决方案资源管理器的右侧,项目下方应是一个名为参考"的节点,如果此列表中缺少系统",请右键单击并选择添加参考".)
我复制了您的代码,并且在我的PC上完全可以正常工作.如果我得到了您提到的3个编译器警告,但是删除了系统引用.
LinkedList是泛型类型,则需要为其提供类型参数.像这样:LinkedList<int> list = new LinkedList<int>();
我忘了输入.
会是
LinkedList< int> list = new LinkedList< int>();
I have written the following code on Linked List :
using System; using System.Collections; using System.Collections.Generic; //using System.Collections.ObjectModel; //using System.Text; class MainClass { static void Main() { LinkedList<int> list = new LinkedList<int>(); list.AddFirst(10); list.AddLast(15); list.AddLast(3); list.AddLast(99); list.AddBefore(list.Last, 25); LinkedListNode<int> node = list.First; while (node != null) { Console.WriteLine(node.Value); node = node.Next; } } }
Whenever I am tring to compile it I am getting the following error:
Error 1 The type or namespace name ''LinkedList'' could not be found (are you missing a using directive or an assembly reference?)
Error 2 The type or namespace name ''LinkedList'' could not be found (are you missing a using directive or an assembly reference?)
Error 3 The type or namespace name ''LinkedListNode'' could not be found (are you missing a using directive or an assembly reference?)
NOTE: I am using Microsoft Visual C# 2008 Express Edition.解决方案Check your references. See if you are missing a reference to System.
(On the right hand side, in Solution Explorer, underneath your project should be a node called "References", if "System" is missing from this list, right click and select "Add Reference".)
I copied your code and it works totally fine on my PC. If I delete the System reference though I get the 3 compiler warnings you mentioned.
LinkedList is a generic type, you need to provide it with a type parameter. Like this:LinkedList<int> list = new LinkedList<int>();
The same for LinkedListNode.
I forget to type.
It will be
LinkedList<int> list = new LinkedList<int>();
这篇关于链表上的编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!