Click here to Skip to main content
15,900,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 22-Jan-10 4:30am
v4

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.
 
Share this answer
 
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.
 
Share this answer
 
I forget to type.
It will be
LinkedList<int> list = new LinkedList<int>();
 
Share this answer
 
v2
Add the right references, do a clean solution and then try again.
 
Share this answer
 
@ Simon Stevens
Thank you very much sir. It is done.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900