Object reference not set to an instance of an object c#
<p>I have the following generic classes (Node and List based on Nodes):</p>

<pre><code>public class Node&lt;T&gt;
    {
        private T info;
        private Node&lt;T&gt; next;

        public Node(T x, Node&lt;T&gt; next)
        {
            this.info = x;
            this.next = next;
        }

        public Node&lt;T&gt; GetNext()
        {
            return this.next;
        }

        public void SetNext(Node&lt;T&gt; next)
        {
            this.next = next;
        }

        public T GetInfo()
        {
            return this.info;
        }

        public void SetInfo(T x)
        {
            this.info = x;
        }

        public override string ToString()
        {
            return this.info.ToString();
        }
    }

    public class List&lt;T&gt;
    {

        private Node&lt;T&gt; first;

        public List()
        {
            this.first = null;
        }

        public Node&lt;T&gt; GetFirst()
        {
            return this.first;
        }

        public Node&lt;T&gt; Add(Node&lt;T&gt; pos, T x)
        {
            Node&lt;T&gt; temp = new Node&lt;T&gt;(x, null);

            if (pos == null)
            {
                temp.SetNext(this.first);
                this.first = temp;
            }
            else
            {
                temp.SetNext(pos.GetNext());
                pos.SetNext(temp);
            }

            return temp;
        }

        public Node&lt;T&gt; Remove(Node&lt;T&gt; pos)
        {
            if (this.first == pos)
                this.first = pos.GetNext();
            else
            {
                Node&lt;T&gt; prevPos = this.GetFirst();
                while (prevPos.GetNext() != pos)
                    prevPos = prevPos.GetNext();
                prevPos.SetNext(pos.GetNext());
            }

            Node&lt;T&gt; nextPos = pos.GetNext();
            pos.SetNext(null);

            return nextPos;
        }


        public override string ToString()
        {
            string str = "[";
            Node&lt;T&gt; pos = this.first;
            while (pos != null)
            {
                str += pos.GetInfo().ToString();
                if (pos.GetNext() != null)
                    str += ", ";
                pos = pos.GetNext();
            }

            str += "]";

            return str;
        }
    }
</code></pre>

<p>What i want to do is two in-class functions for List class.
- The first function will sum up all the numbers in the List which are at even position.
- The second function will check up whether the List is sorted in alphabetical order.</p>

<p>What I've done:</p>

<pre><code>   public int SumElementsOnEven()
    {
        int sum = 0;
        Node&lt;T&gt; pos = this.first;
        while (pos != null)
        {
            sum += int.Parse(pos.GetInfo().ToString());
            pos = pos.GetNext().GetNext();
        }
        return sum;
    }

    public bool isAlpha()
    {
        Node&lt;T&gt; pos = this.first;
        while (pos != null)
        {
            string a = pos.GetInfo().ToString();
            string b = pos.GetNext().GetInfo().ToString();
            if (a[0] &lt; b[0])
                return false;
            pos = pos.GetNext();
        }

        return true;
    }
</code></pre>

<p>But it returns error in both of them. </p>

<blockquote>
  <p>Object reference not set to an
  instance of an object.</p>
</blockquote>

<p>In the place where i do twice:</p>

<pre><code>GetNext().GetNext();
</code></pre>

<p>This skipping one more element.
And the second error in the place:</p>

<pre><code>string b = pos.GetNext().GetInfo().ToString();
</code></pre>

<p>Because i want to compare two elements.
Basically it's like saving reference from reference or maybe I'm wrong?
Anyways, How can i solve this?</p>
