问题描述
我有一个名为CurrentPage(例如B类型)的属性,该属性绑定到HeaderedContentControl的内容.
并且我有一个名为MyPages的B类型集合(所有实例都在这里创建一次).
现在当我说CurrentPage = MyPages [0];它会创建一个新实例,尽管它不会创建一个实例.
用同样的方式当我说CurrentPage = MyPages [1];再次创建一个新实例.
我不明白为什么要这么做.
每次我执行上述任务时,它都会消耗内存.
这是什么原因?
预先谢谢您
Hi,
I have a property named CurrentPage(eg: B type) bound to Content of HeaderedContentControl.
and I have a collection of B type named MyPages (All the instances have been created here once).
Now when I say CurrentPage = MyPages[0]; it creates a new instance though it does not go to create one.
Same way When I say CurrentPage = MyPages[1]; again it creates a new instance.
I am not getting why it does this.
It consumes memory every time I do above kind of assignment.
What would be the cause here?
Thank you in advance
推荐答案
public class MyPagesCollection
{
private List<page> _innerList = new List<page>();
public this[int index]
{
get
{
Page page = _innerList[index].Copy();
DoSomethingImportantWith(page);
return(page);
}
}
}</page></page>
通常,很难不看相关的代码.
In general, it''s hard to say without seeing the relevant code.
这篇关于每次在HeaderedContentControl中创建新实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!