jer*_*ron 2 c# oop data-structures
我正在开展一个需要跟踪的项目:
我想过可能会使用一个字典,其中Key是一个字符串,而Values是对象列表.或者为每个根项创建一个唯一的类,每个类将包含一个子列表.
有没有人有任何好的建议?我对OOP还很新,请耐心等我:)
谢谢!
public interface IRoot {}
public class RootItem<T> : IRoot
{
public string Name { get; set; }
public List<T> Children {get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后保持一个Dictionary<string, IRoot>把握住它们.
Dictionary<string, IRoot> hair = new Dictionary<string, IRoot>();
hair.Add(
new RootItem<int>()
{
Name = "None",
Children = new List<int>() {1, 2, 3, 4}
}
);
hair.Add(
new RootItem<decimal>()
{
Name = "None",
Children = new List<decimal>() {1m, 2m, 3m, 4m}
}
);
Run Code Online (Sandbox Code Playgroud)