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
  • 39,551
  • 56
  • 175
  • 291
Westerlund.io
  • 2,743
  • 5
  • 30
  • 37

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
  • 29,350
  • 9
  • 53
  • 99