Shane Shane - 4 months ago 37
C# Question

Creating a very simple linked list

I am trying to create a linked list just to see if I can, and I am having trouble getting my head around it. Does anyone have an example of a very simple implementation of Linked list using C#? All the examples I have found so far are quite overdone.


A Linked List, at its core is a bunch of Nodes linked together.

So, you need to start with a simple Node class:

public class Node {
    public Node next;
    public Object data;

Then your linked list will have as a member one node representing the head (start) of the list:

public class LinkedList {
    private Node head;

Then you need to add functionality to the list by adding methods. They usually involve some sort of traversal along all of the nodes.

public void printAllNodes() {
    Node cur = head;
    while ( != null) 
        cur =;

Also, inserting new data is another common operation:

public void Add(Object data) {
    Node toAdd = new Node(); = data;
    Node current = head;
    // traverse all nodes (see the print all nodes method for an example)
    current.Next = toAdd;

This should provide a good starting point.