-3

first time posting on here and a bit of a noob in c#. Basically I'm creating a linkedlist and initializing it to null at the beginning of my class. When I'm ready to use it, I check to make sure that it's not equal to the string passed by the method. I immediately get a NullReferenceException, and i'm supposed to be comparing it to null. Any fixes?

private DoubleLinkedListCell<DoubleLinkedListCell<GamePiece>> _columns = null;

public void FindColumn(string columnId)
    {

        bool right = true;
        while (_columns.Id != columnId)
        {
            if (_columns.Next == null)
            {
                right = false;
            }
            if (right)
            {
                Columns = Columns.Next;
            }
            else
            {
                Columns = Columns.Prev;
            }
        }

    }
Sofa3535
  • 17
  • 5

1 Answers1

0

You will get null reference if u try to access any property or member of _columns List (ex _columns.Id,_columns.Next etc..) so initialize it in constructor or direct when u declare field

G.L
  • 109
  • 3
  • 15