Sets the value of the entry at the specified index of NameObjectCollectionBase : NameObjectCollectionBase « Collections Data Structure « C# / C Sharp






Sets the value of the entry at the specified index of NameObjectCollectionBase

 

using System;
using System.Collections;
using System.Collections.Specialized;

public class MyCollection : NameObjectCollectionBase  {
   public Object this[ int index ]  {
      get  {
         return( this.BaseGet( index ) );
      }
      set  {
         this.BaseSet( index, value );
      }
   }
   public Object this[ String key ]  {
      get  {
         return( this.BaseGet( key ) );
      }
      set  {
         this.BaseSet( key, value );
      }
   }
   public String[] AllKeys  {
      get  {
         return( this.BaseGetAllKeys() );
      }
   }
   public MyCollection( IDictionary d )  {
      foreach ( DictionaryEntry de in d )  {
         this.BaseAdd( (String) de.Key, de.Value );
      }
   }

}

public class SamplesNameObjectCollectionBase  {
   public static void Main()  {
      IDictionary d = new ListDictionary();
      d.Add( "A", "a" );
      d.Add( "B", "b" );
      d.Add( "C", "C" );
      MyCollection myCol = new MyCollection( d );
      PrintKeysAndValues2( myCol );
      Console.WriteLine();
      myCol[1] = "sunflower";
      PrintKeysAndValues2( myCol );
      Console.WriteLine();
      myCol["red"] = "tulip";
      PrintKeysAndValues2( myCol );
   }
   public static void PrintKeysAndValues2( MyCollection myCol )  {
      foreach ( String s in myCol.AllKeys )  {
         Console.WriteLine( "{0}, {1}", s, myCol[s] );
      }
   }

}

   
  








Related examples in the same category

1.NameObjectCollectionBase Demo
2.NameObjectCollectionBase is the base class for a collection of associated String keys and Object values
3.Adds an entry with the specified key and value into NameObjectCollectionBase
4.Removes all entries from NameObjectCollectionBase
5.Gets the value of the entry at the specified index of NameObjectCollectionBase
6.Returns a String array that contains all the keys in NameObjectCollectionBase
7.Whether NameObjectCollectionBase contains entries whose keys are not null.
8.Removes the entries with the specified key from NameObjectCollectionBase
9.Whether NameObjectCollectionBase is read-only.
10.Represents a collection of associated String keys and String values