1

クローン可能な「長い」の代わりに何を使用できますか?

ここでエラーが発生しているコードを以下に参照してください。

public static CloneableDictionary<string, long> returnValues = new CloneableDictionary<string, long>();

編集:見つけた次のコードを使用したかったことを忘れていました(以下を参照)。

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;
    }
}
4

2 に答える 2

6

のクローンを作成しても意味がありませんlong

通常のDictionary<string, long>.

辞書自体を複製したい場合は、 と書くことができますnew Dictionary<string, long>(otherDictionary)

于 2010-08-12T01:36:41.113 に答える
1
public class CloneableDictionary<TKey, TValue> : Dictionary<TKey, TValue>
{
    public IDictionary<TKey, TValue> Clone()
    {
        var clone = new CloneableDictionary<TKey, TValue>();

        foreach (KeyValuePair<TKey, TValue> pair in this)
        {
            ICloneable clonableValue = pair.Value as ICloneable;
            if (clonableValue != null)
                clone.Add(pair.Key, (TValue)clonableValue.Clone());
            else
                clone.Add(pair.Key, pair.Value);
        }

        return clone;
    }
}
于 2010-08-12T01:52:58.477 に答える