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
}
}
Static class, NullReferenceException [duplicate]
-
17-07-2023 - |
سؤال
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;
}
}
}
المحلول
لا تنتمي إلى StackOverflow