Gre*_*reg 1 c# cloneable long-integer
我可以使用什么代替可以克隆的"长"?
请参阅下面我在此处收到错误的代码,因为长期不可克隆.
public static CloneableDictionary<string, long> returnValues = new CloneableDictionary<string, long>();
Run Code Online (Sandbox Code Playgroud)
编辑:我忘了提到我想使用我找到的以下代码(见下文).
public class CloneableDictionary<TKey, TValue> : Dictionary<TKey, TValue> where TValue : ICloneable
{
public IDictionary<TKey, TValue> Clone()
{
var clone = new CloneableDictionary<TKey, TValue>();
foreach (KeyValuePair<TKey, TValue> pair in this)
{
clone.Add(pair.Key, (TValue)pair.Value.Clone());
}
return clone;
}
}
Run Code Online (Sandbox Code Playgroud)
克隆没有意义long.
你应该使用常规Dictionary<string, long>.
如果要克隆字典本身,可以编写new Dictionary<string, long>(otherDictionary).
| 归档时间: |
|
| 查看次数: |
165 次 |
| 最近记录: |