Marco

Marco

  • NA
  • 59
  • 0

allocating objects in C#

Oct 30 2007 6:20 AM
Hello, I'm a newbie C#er...
I have just one question: I'm trying to code my own linked list;
I tried to write in C# and after I'll explain my doubt:

class Node {
    public Node (int v) { next = null; val =n; }
    Node next;   
    int val;
   
}

class LinkedList {
     LinkedList () {start=null;}
     Node start;
     public  addNode( Node n) { if (start = null) start = n; else ......}
}
//main
LinkedList l = new LinkedList();
l.add (new Node (10));
...........................

Now: we focus on insert of first Node..... start node will take '10' but I don't initialized anywhere 'start' object. Is it right? Shouldn't be something like start = new Node () anywhere?
I hope you'll understand....
thanks...

Answers (4)