Whether NameObjectCollectionBase contains entries whose keys are not null.
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() {
}
public void Add( String key, Object value ) {
this.BaseAdd( key, value );
}
public Boolean HasKeys {
get {
return( this.BaseHasKeys() );
}
}
}
public class SamplesNameObjectCollectionBase {
public static void Main() {
MyCollection myCol = new MyCollection();
Console.WriteLine( "Initial state of the collection (Count = {0}):", myCol.Count );
PrintKeysAndValues( myCol );
Console.WriteLine( "HasKeys? {0}", myCol.HasKeys );
myCol.Add( "blue", "sky" );
Console.WriteLine( "Initial state of the collection (Count = {0}):", myCol.Count );
PrintKeysAndValues( myCol );
Console.WriteLine( "HasKeys? {0}", myCol.HasKeys );
}
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 );
}
}
}
Related examples in the same category