Forbid public Add and Delete for a List

前端 未结 8 1795
被撕碎了的回忆
被撕碎了的回忆 2021-02-19 02:11

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:52

    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.

提交回复
热议问题