Properly exposing a List?

前端 未结 8 1545
谎友^
谎友^ 2021-02-02 01:20

I know I shouldn\'t be exposing a List in a property, but I wonder what the proper way to do it is? For example, doing this:

public static          


        
8条回答
  •  [愿得一人]
    2021-02-02 01:28

    Yes and No. Yes, there is a performance overhead, because a new object is created. No, your list is not cloned, it is wrapped by the ReadOnlyCollection.

提交回复
热议问题