Why Dictionary is serializable ?
Does anyone know the reason why Dictionary is serializable ?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Roei BarRank #1,271 · 1.4K reputationPosted Sep 4, 2009, 1:31 PM EDT
Master BillaRank #2,229 · 630 reputationPosted Sep 4, 2009, 7:42 PM EDT
When you are look .net class lib for the dictonarty, it inherited from some basic object. take look the snap shot
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace System.Collections.Generic
{
// Summary:
// Represents a collection of keys and values.
//
// Type parameters:
// TKey:
// The type of the keys in the dictionary.
//
// TValue:
// The type of the values in the dictionary.
[Serializable]
[ComVisible(false)]
[DebuggerDisplay("Count = {Count}")]
public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IDictionary, ICollection, IEnumerable, ISerializable, IDeserializationCallback
{
// Summary:
// Initializes a new instance of the System.Collections.Generic.Dictionary
// class that is empty, has the default initial capacity, and uses the default
// equality comparer for the key type.
public Dictionary();
//
// Summary:
// Initializes a new instance of the System.Collections.Generic.Dictionary
// class that contains elements copied from the specified System.Collections.Generic.IDictionary
// and uses the default equality comparer for the key type.
//
// Parameters:
// dictionary:
// The System.Collections.Generic.IDictionary whose elements are
// copied to the new System.Collections.Generic.Dictionary.
//
// Exceptions:
// System.ArgumentNullException:
// dictionary is null.
//
// System.ArgumentException:
// dictionary contains one or more duplicate keys.
}
}
Thank you
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Sep 4, 2009, 11:56 PM EDT
So if you need a keyed list and your objects include unique values, you can use KeyedCollection and get the benefits of serialization as well.
You also can check it out:
1.http://www.c-sharpcorner.com/Blogs/BlogDetail.aspx?BlogId=362