Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 静态类,NullReferenceException_C#_Static_Nullreferenceexception - Fatal编程技术网

C# 静态类,NullReferenceException

C# 静态类,NullReferenceException,c#,static,nullreferenceexception,C#,Static,Nullreferenceexception,为什么这里会出现NullReferenceException 我还尝试使用静态构造函数,但也没有用。当我在方法中放置断点时,我只看到“Command c”变量,而没有看到这个静态类的变量 static class TableManager { public static Dictionary<Guid, Table.AbstractTable> Tables = new Dictionary<Guid, AbstractTable>(); public

为什么这里会出现NullReferenceException

我还尝试使用静态构造函数,但也没有用。当我在方法中放置断点时,我只看到“Command c”变量,而没有看到这个静态类的变量

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;
        }
    }
}
静态类表管理器
{
公共静态字典表=新字典();
公共静态boolcreateTable(命令c)
{
if(!Tables.ContainsKey(c.Table.TableID))
{
//变魔术
返回真值
}
其他的
{
//表已存在,返回false。
返回false;
}
}
}

c或
c.Table
为空。Tables中没有任何内容
c.Table.TableID
的断点显示了什么?@DavidCrowell and DStanley谢谢。桌子是空的!我看错了方向!
 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
         }
  }