C# - List member needs deep copy?

后端 未结 3 1944
独厮守ぢ
独厮守ぢ 2021-01-12 19:51

I have class with a List member. If I want to clone an instance of this class, do I need a deep copy or the MemberwiseClone() shallow co

3条回答
  •  时光取名叫无心
    2021-01-12 20:08

    Short answer, yes.

    Long answer, you need to determine what the copy in your case actually means with respect to the list. Do you need a copy of the contents of the list as well? For value types like ints, its pretty straight forward, if it were reference types though....yo have some questions to ask regarding what you want your list to contain.

提交回复
热议问题