我想确认对https://stackoverflow.com/a/10387423/368896的回答是正确的,并且适用于以下情况:
// These IDataHolder instances contains a property "name",
// and another data member that is a large array.
// A copy constructor exists that makes a deep copy.
public MyFunction(IEnumerable<IDataHolder> columns)
{
// Is the copy constructor called?
this.columns = columns.ToDictionary(c => c.info.name, c => c);
}
我相当有信心复制构造函数没有被调用;即,调用toDictionaary
不执行深层复制,而只复制引用。
但是,我找不到对此的确认。
我对么?是否toDictionary()
只执行浅拷贝?
(注意:我有很强的 C++ 背景,但对 C# 很陌生。)