As Greg indicated, here is an example of a "DictionaryHashList" that does
what you want:
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
namespace System.Collections.Specialized
{
public class DictionaryHashList : NameObjectCollectionBase
{
private DictionaryEntry _de = new DictionaryEntry();
// Creates an empty collection.
public DictionaryHashList()
{
}
// Adds elements from an IDictionary into the new collection.
public DictionaryHashList( IDictionary d, Boolean bReadOnly )
{
foreach ( DictionaryEntry de in d )
{
this.BaseAdd( (String) de.Key, de.Value );
}
this.IsReadOnly = bReadOnly;
}
// Gets a key-and-value pair (DictionaryEntry) using an index.
public DictionaryEntry this[ int index ]
{
get
{
_de.Key = this.BaseGetKey(index);
_de.Value = this.BaseGet(index);
return( _de );
}
}
// Gets or sets the value associated with the specified key.
public Object this[ String key ]
{
get
{
return( this.BaseGet( key ) );
}
set
{
this.BaseSet( key, value );
}
}
// Gets a String array that contains all the keys in the collection.
public String[] AllKeys
{
get
{
return( this.BaseGetAllKeys() );
}
}
// Gets an Object array that contains all the values in the collection.
public Array AllValues
{
get
{
return( this.BaseGetAllValues() );
}
}
// Gets a String array that contains all the values in the collection.
public String[] AllStringValues
{
get
{
return( (String[]) this.BaseGetAllValues( Type.GetType( "System.String"
) ) );
}
}
// Gets a value indicating if the collection contains keys that are not
null.
public Boolean HasKeys
{
get
{
return( this.BaseHasKeys() );
}
}
// Adds an entry to the collection.
public void Add( String key, Object value )
{
this.BaseAdd( key, value );
}
// Removes an entry with the specified key from the collection.
public void Remove( String key )
{
this.BaseRemove( key );
}
// Removes an entry in the specified index from the collection.
public void Remove( int index )
{
this.BaseRemoveAt( index );
}
// Clears all the elements in the collection.
public void Clear()
{
this.BaseClear();
}
}
}
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Lamis" wrote:
Hi,
I have a hashtabel m_haschtbl = new Hashtable();
I need to get out my objects from my hashtable in the same order like they
were stored. the order is very important..
I have used IDictionaryEnumerator en = m_hasctbl.GetEnumerator();
while (en.MoveNext())
{
m_object = en.value;
// do some work here
}
is there any way to sort my objects???
thanks
is there
--
LZ