A friend and I (both new in programming) were arguing if it was wise to include a Dictionary inside a Class that contains all instances of that class.
I say that is better that the dictionary is in the main instead in the class itself.
我没有充分的理由说出为什么,但是我从未见过有类记录已创建对象的记录。
您能给我每种方法的利弊吗?
提前致谢。
A:
class Table
{
public static Dictionary<int,Table> Tables = new Dictionary<int, Table>();
...
public table (int ID) // constructor
{
...
Tables.Add(ID,this);
}
}
Run Code Online (Sandbox Code Playgroud)
B:
class Program
{
public Dictionary<int,Table> Tables = …Run Code Online (Sandbox Code Playgroud)