4
Answers

allocating objects in C#

Marco

Marco

17y
20.7k
1
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)