Implementation of Linked List I had implemented a simple Linked list Insert, print and insert at the nth position. It works fine.
Could someone review code and let me know where I could have done better (or) where I had gone wrong?




class Linkedlist
     {
       public Nodes current;
       public static Nodes headnode;
       public static int nodecount;
       public void Addatfirst(object d)
      {

          if (headnode == null)
          {
              headnode = new Nodes(d);
              nodecount++;
           }
          else
          {
              Nodes dummy = new Nodes(d);
              dummy.Next = headnode;
              headnode = dummy;
              nodecount++;
           }
         }

     public void Print()
    {
        current = headnode;

        while (current.Next != null)
        {
            Console.Write("|" + current.data + "| -&gt; ");
            current = current.Next;
            if (current.Next == null)
            {
                Console.Write("|" + current.data + "| -&gt; ");
            }
        }
    }

    public void AddatLast(object d)
    {
        current = headnode;
        while (current.Next != null)
        {
            current = current.Next;
            if (current.Next == null)
            {
                current.Next = new Nodes(d);
                nodecount++;
                return;
            }
        }
    }

    public void AddatNthPosition(object d, int position)
    {
        current = headnode;
        for (int i = 1; i &lt; position; i++)
        {
            current = current.Next;
            if (position - i == 1)
            {
                var temp= new Nodes(d);
                temp.Next = current.Next;
                current.Next = temp;
            }
        }
    }
}
public class Nodes
{
    public object data;
    public Nodes Next;
    public Nodes(object d)
    {
        data = d;
    }
}
There are actually several bugs in your code. Your list is also not very easy to use because it can't be iterated.

Bugs


static fields are shared among class instances. So if you create multiple Linkedlist instances, they will all use the same headnode and nodecount. That is obviously not what you want. Those fields should not be static.
AddatNthPosition doesn't add anything if you pass 0 or 1 as index. Also, it throws a NullReferenceException when given an index that is too large. Throwing an ArgumentOutOfRangeException would be better if the index is too small (negative) or too large.
Only Addatfirst takes into account that the list can be empty. The other add methods fail with a NullReferenceException when called on an empty list.


Problems


Your list cannot be iterated because it does not implement IEnumerable. That makes it difficult to use: instead of using foreach or Linq, calling code is forced to manually walk through its nodes. While you're at it, implementing ICollection (count) and IList (indexing, adding, inserting, removing) may also be useful.
public fields can be modified by other code. That means that some other code could replace the head node of a linked list, or adjust its count. That can easily cause bugs or other unexpected behavior. Classes should hide their internal state and implementation details.
Print may be useful for debugging, but it should not be part of your (final) list class. Classes should (ideally) have only a single responsibility, and 'storing items' and 'displaying things' are different things as far as I'm concerned.
Why is there a current field? It looks like that should be a local variable in some of your methods.


Improvements


Consider making your class generic. This improves type safety and makes your list easier to work with.
Try sticking to the official naming conventions to make your code easier to read. C# code uses PascalCase for class and method names: LinkedList instead of Linkedlist, AddToStart instead of AddtoStart, and so on. camelCase is used for field names: headNode instead of headnode, nodeCount instead of nodecount, and so on.
Try using more descriptive names. value instead of d, newNode instead of dummy, and so on. Also, Nodes is plural, but it represents a single node, so it should be named Node instead.
Look at the collections in the standard library. They often use particular names for their methods, and that's what other programmers will be familiar with. Using different names makes your code harder to use. Consider renaming AddatLast to Add, and combining Addatfirst and AddatNthPosition into a single Insert method (where its first argument is the index, conform the IList interface). Also rename nodecount to Count and make it a get-only property, so it can't be modified by other code.
A Remove and/or RemoveAt method would make your list more useful.
If adding items at the end is important, consider adding a lastNode field to improve performance for that case.
Inconsistent indentation makes code harder to read, and it looks a little sloppy.