using System;
using System.Collections;
using System.Collections.Specialized;
public class MyCollection : NameObjectCollectionBase {
private DictionaryEntry _de = new DictionaryEntry();
public DictionaryEntry this[ int index ] {
get {
_de.Key = this.BaseGetKey( index );
_de.Value = this.BaseGet( index );
return( _de );
}
}
public MyCollection( IDictionary d, Boolean bReadOnly ) {
foreach ( DictionaryEntry de in d ) {
this.BaseAdd( (String) de.Key, de.Value );
}
this.IsReadOnly = bReadOnly;
}
public void Add( String key, Object value ) {
this.BaseAdd( key, 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 myROCol = new MyCollection( d, true );
myROCol.Add( "Q", "q" );
PrintKeysAndValues( myROCol );
}
public static void PrintKeysAndValues( MyCollection myCol ) {
for ( int i = 0; i < myCol.Count; i++ ) {
Console.WriteLine( "[{0}] : {1}, {2}", i, myCol[i].Key, myCol[i].Value );
}
}
}