Forbid public Add and Delete for a List

前端 未结 8 1198
我在风中等你
我在风中等你 2021-02-19 02:12

in my C#-project, I have a class which contains a List

public class MyClass
{
  public MyClass parent;
  public List children;
  ...
}
         


        
8条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-19 02:40

    You don't need to reimplemented IList, just encapsulate a List in a class, and provide your own Add and Delete functions, that will take care of adding and setting the required properties.

    You might have to create your own enumerator if you want to enumerate through the list though.

提交回复
热议问题