help needed for Dictionary concept
C#
2
Posts
2
Posters
0
Views
1
Watching
-
hi, i am new in c#,how to add values in below Dictionary private Dictionary> batchTable = new Dictionary>(); parthiban
I have two different ways:
// Cleaner less controll over the dictionary private Dictionary<> innerTable; private Dictionary<>>> outterTable; public DataAccessLayer() { innerTable = new Dictionary<>(); outterTable = new Dictionary<>>>(); innerTable.Add( "stringKey", 12312.012 ); outterTable.Add( "anotherStringKey", innerTable ); } // Longer but you'll define both dictionaries // and how all the methods work. public class UsingMyNewCollections { // default constructor public UsingMyNewCollections() { InnerDictionary inner = new InnerDictionary(); inner.Add( "StringKey", 1213.0123D ); OutterDictionary outter = new OutterDictionary(); batchTable.Add( "SomeKeyString", outter ); } } public class OutterDictionary : IDictionary<> { // private field for the class private Dictionary<> m_outterDictionary; // default constructor public OutterDictionary() { m_outterDictionary = new Dictionary<>(); } public void Add( string key, InnerDictionary value ) { // Validation on passed in values // ... // Add your value m_outterDictionary.Add( key, value ); } #region IDictionary<> Members // code #endregion #region ICollection<>>> Members // code #endregion #region IEnumerable<>>> Members // code #endregion #region IEnumerable Members //code #endregion } public class InnerDictionary : IDictionary<> { // private field for the class private Dictionary<> m_innerDictionary; // default constructor public InnerDictionary() { m_innerDictionary = new Dictionary<>(); } &n