Forbid public Add and Delete for a List

前端 未结 8 1222
我在风中等你
我在风中等你 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:55

    Use List(T).AsReadOnly().

    http://msdn.microsoft.com/en-us/library/e78dcd75.aspx

    Returns a read-only IList<(Of <(T>)>) wrapper for the current collection.

    Available since .NET 2.0.

提交回复
热议问题