-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: KartikKrish
Message 3 in Discussion
Did you try using a ListDictionary? You can also try this code-> using System;
using System.Collections;
class BaseEnumerator : IEnumerator
{
protected IEnumerator e;
public BaseEnumerator(IEnumerator enumerator)
{
e = enumerator;
}
public virtual object Current
{
get
{
return e.Current;
}
}
public virtual bool MoveNext()
{
return e.MoveNext();
}
public virtual void Reset()
{
e.Reset();
}
}
class IgnoreNullEnumerator : BaseEnumerator
{
public IgnoreNullEnumerator(IEnumerator enumerator) : base(enumerator) { }
public override object Current
{
get
{
while (e.Current == null && e.MoveNext()) ;
return e.Current;
}
}
}
class IgnoreNullArrayList : ArrayList
{
public override IEnumerator GetEnumerator()
{
return new IgnoreNullEnumerator(base.GetEnumerator());
}
}
class MyHashArray : IDictionary
{
private ArrayList m_List = new IgnoreNullArrayList();
private Hashtable m_Hash = new Hashtable();
class MyDictionaryEnumerator : BaseEnumerator, IDictionaryEnumerator
{
ArrayList a;
public MyDictionaryEnumerator(IDictionaryEnumerator dictionaryEnum,
ArrayList <NOBR>array</NOBR>) : base(dictionaryEnum)
{
a = array;
}
public override object Current
{
get
{
return Entry;
}
}
public DictionaryEntry Entry
{
get
{
return new DictionaryEntry( ((DictionaryEntry) e.Current).Key,
a[(int) ((DictionaryEntry) e.Current).Value]);
}
}
public object Key
{
get
{
return ((DictionaryEntry) e.Current).Key;
}
}
public object Value
{
get
{
return a[(int) ((DictionaryEntry) e.Current).Value];
}
}
}
public object this[object key]
{
get
{
if (m_Hash.Contains(key))
return m_List[(int) m_Hash[key]];
else
return null; // may want to throw an exception
}
set
{
if (m_Hash.Contains(key))
{
m_List[(int) m_Hash[key]] = value;
}
else
{
Add(key, value);
}
}
}
public ICollection Keys
{
// Iterates by internal hash table storage order
get
{
return m_Hash.Keys;
}
}
public ICollection Values
{
// Iterates by insertion order
get
{
return m_List;
}
}
public bool IsReadOnly
{
get
{
return false;
}
}
public bool IsFixedSize
{
get
{
return false;
}
}
public int Count
{
get
{
return m_Hash.Count;
}
}
public bool IsSynchronized
{
get
{
return m_List.IsSynchronized && m_Hash.IsSynchronized;
}
}
public void Add(object key, object value)
{
m_Hash.Add(key, m_List.Add(value));
}
public void Clear()
{
m_List.Clear();
m_Hash.Clear();
}
public void Remove(object key)
{
if (m_Hash.Contains(key))
{
m_List[(int) m_Hash[key]] = null;
m_Hash.Remove(key);
}
}
public bool Contains(object key)
{
return m_Hash.Contains(key);
}
public IDictionaryEnumerator GetEnumerator()
{
return new MyDictionaryEnumerator(m_Hash.GetEnumerator(), m_List);
}
IEnumerator IEnumerable.GetEnumerator()
{
return m_List.GetEnumerator();
}
public IEnumerator GetItemEnumerator()
{
return m_List.GetEnumerator();
}
public void CopyTo(Array array, int index)
{
m_List.CopyTo(array, index);
}
public object SyncRoot
{
get
{
return m_Hash.SyncRoot;
}
}
}
public class Example
{
public static void Main()
{
MyHashArray myElements = new MyHashArray();
myElements["one"] = "element 1";
myElements["two"] = "element 2";
myElements["three"] = "element 3";
Dump(myElements);
myElements["three"] = "element 3 modified";
myElements.Remove("two");
myElements["four"] = "element 4";
myElements["five"] = "element 5";
Dump(myElements);
}
public static void Dump(IDictionary h)
{
Console.WriteLine("As Inserted: ");
foreach (object element in h.Values)
{
Console.WriteLine(element);
}
Console.WriteLine();
Console.WriteLine("As enumerated by hash: ");
foreach (DictionaryEntry element in h)
{
Console.WriteLine(element.Key + " => " + element.Value);
}
Console.WriteLine();
}
}
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]