ObservableCollection(List) 文档中的复制是什么意思

发布于 01-16 18:30 字数 732 浏览 1 评论 0原文

我有 2 个容器:

List<T>
ObservableCollection<T>

我使用 List 的过滤部分构造 ObservableCollection 容器。我查看了构造函数的文档: ObservableCollection(List) 此处。 在这个文档中这样写:

初始化 ObservableCollection 类的新实例,其中包含从指定列表复制的元素。

但我不知道 copied 这个词是否意味着真正的内存复制或将 List 中的项目值引用到 ObservableCollection< /代码>?

I have 2 containers as:

List<T>
ObservableCollection<T>

I construct the ObservableCollection<T> containers with a filtred part of List<T>. I took a look the documentation of the constructor: ObservableCollection<T>(List<T>) here.
In this docummentation this is write:

Initializes a new instance of the ObservableCollection class that contains elements copied from the specified list.

But I don't know if the word copied mean real memory copy or referencing the value of item in the List<T> into the ObservableCollection<T> ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间不值得2025-01-23 18:30:18

正如评论@Ralf 中所说:

这取决于 T 是什么。对于值类型,您会得到一个副本。对于引用类型,您仍然引用同一个对象。

有关 ReferenceType 和 < a href="https://learn.microsoft.com/fr-fr/dotnet/api/system.valuetype?view=net-6.0" rel="nofollow noreferrer">ValueType

As said in the comment @Ralf:

That depends of what T is. For a valuetype you get a copy. For a referencetype you still reference the same object.

More info about ReferenceType and ValueType

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文