0

Why do I get a NullReferenceException here?

I also tried to use a static constructor but that didn't help either. When I put a breakpoint within the method I only see the "Command c" variables but not the variables for this static class.

static class TableManager
{
    public static Dictionary<Guid, Table.AbstractTable> Tables = new Dictionary<Guid, AbstractTable>();

    public static bool CreateTable(Command c)
    {
        if (!Tables.ContainsKey(c.Table.TableID))
        {
            //Do magic
            return true
        }
        else
        {
            //Table already exists, return false.
            return false;
        }
    }
}
Uwe Keim
  • 36,867
  • 50
  • 163
  • 268
Westerlund.io
  • 2,351
  • 4
  • 22
  • 36

1 Answers1

1
 public static bool CreateTable(Command c)
 {
        if(c != null && c.Table != null)
        {
             if (!Tables.ContainsKey(c.Table.TableID))
             {
                 //Do magic
                 return true
             }
             else
             {
                //Table already exists, return false.
                return false;
             }
         }
         else
         {
             //Ouch!! c or c.Table are null man
         }
  }
Amir Popovich
  • 26,624
  • 8
  • 44
  • 88