Re: Create a custom collection



| I implemented a class called MyDictionary that inherits from
DictionaryBase.
| The thing is that my class, cannot handle a duplicate value in the "keys"

Have you tried inheriting from
System.Collections.Specialized.NameValueCollection?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsspecializednamevaluecollectionclasstopic.asp

Unfortunately it wants strings & not objects.

You could code your Add such that if you are adding a duplicate that it
changes that entry to a list and adds the duplicates to the list.
Unfortunately this complicates the indexer's & enumerators as sometimes you
are returning a single object, sometimes multiple objects.

Have you considered defining MyDictionary to be a dictionary of an array of
your objects? Where each key holds an array (ArrayList?) of one or more
objects?


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


"Mike" <mike@xxxxxxxxxxx> wrote in message
news:OF9fzCgFGHA.2652@xxxxxxxxxxxxxxxxxxxxxxx
| Hello guys, how are you?
|
|
|
| I implemented a class called MyDictionary that inherits from
DictionaryBase.
|
| The thing is that my class, cannot handle a duplicate value in the "keys"
|
|
|
| Like;
|
|
|
| Dim md as New MyDictionary
|
| md.add("Mike", Object1)
|
| md.add("Mike", Object2)
|
|
|
| This will generate an error during compilation, because I cannot add Mike
| two times to the collection, we all know that.
|
| I need to come up with something (like a custom made collection or
| structure) that allow me to do this.
|
| I need a key (string type, can be duplicate) and a value (object type,
like
| an instance of another class).
|
|
|
| Could you please help me on this, any example will be highly appreciated!
|
|
|
| Mike
|
|


.



Relevant Pages

  • Re: Create a custom collection
    ... > DictionaryBase. ... > You could code your Add such that if you are adding a duplicate that it ... > | I implemented a class called MyDictionary that inherits from ... > | Mike ...
    (microsoft.public.dotnet.languages.vb)
  • Re: UIManager.put() allows duplicates ????
    ... The UIDefaults class which inherits the Hashtable allows duplicate ... keys. ...
    (comp.lang.java.gui)
  • Re: how to parse INI files ?
    ... >> What of duplicate sections? ... > I allowed duplicate keys; and if the value associated with the duplicate ... When multiple spaces are found within section names and keys, ... Michel Bardiaux ...
    (comp.lang.c)
  • Re: how to parse INI files ?
    ... > What of duplicate sections? ... I allowed duplicate keys; and if the value associated with the ... Multiple spaces within ... I maintained the order of /first instance/ of sections and KVPs ...
    (comp.lang.c)
  • Re: Thanks!
    ... I realize my concept of keys might be slightly askew. ... > a number and not having to worry about the user assigning duplicate ... on "surrogate keys" would return you some interesting, and lively, ... and interview the 'offending' employee. ...
    (microsoft.public.access.tablesdbdesign)