Linda,

> This is a collection of objects, so can the value in the value/key pair be a
pointer to an object or do I need a more complex class.

It can.

> I found a class called System.Collections.Specialized.NameObjectCollectionBase which 
>seems to do the trick for the keying portion, but am having difficulty getting a 
>for/each to work with that one.

These snippets show how to enumerate the items of a 
SpecializedNameObjectCollectionBase object. NameValueCollection inherits from 
SpecializedNameObjectCollectionBase.

  [C#]

  using System;
  using System.Collections.Specialized;


  public class Test {
      public static void Main() {
          NameValueCollection collection = new NameValueCollection();

          collection.Add("first", "foo");
          collection.Add("second", "bar");

          foreach (string key in collection) {
              Console.WriteLine(collection[key]);
          }
      }
  }



  [Visual Basic]

  Imports System
  Imports System.Collections.Specialized


  Public Class Test
      Public Shared Sub Main()
          Dim collection As New NameValueCollection()
          Dim key As String

          collection.Add("first", "foo")
          collection.Add("second", "bar")

          For Each key In collection
              Console.WriteLine(collection(key))
          Next
      End Sub
  End Class




  [JScript]

  import System;
  import System.Collections.Specialized;


  var collection: NameValueCollection = new NameValueCollection();

  collection.Add("first", "foo");
  collection.Add("second", "bar");

  for (var key: String in collection) {
      print(collection.Item(key));
  }

HTH,

Stefan

  ----- Original Message ----- 
  From: Linda Farrington 
  To: Moderated discussion of advanced .NET topics. 
  Sent: Tuesday, August 20, 2002 10:03 PM
  Subject: RE: [ADVANCED-DOTNET] using system.collections in .net


  This is a collection of objects, so can the value in the value/key pair be a
  pointer to an object or do I need a more complex class.  I found a class
  called System.Collections.Specialized.NameObjectCollectionBase which seems
  to do the trick for the keying portion, but am having difficulty getting a
  for/each to work with that one.

  Linda

  -----Original Message-----
  From: Moderated discussion of advanced .NET topics.
  [mailto:[EMAIL PROTECTED]]On Behalf Of Christoph
  Schittko
  Sent: Saturday, August 17, 2002 7:35 PM
  To: [EMAIL PROTECTED]
  Subject: Re: [ADVANCED-DOTNET] using system.collections in .net


  How about System.Collections.DictionaryBase, but then you always have to
  provide a key( or generate a unique one if the optional parameter was not
  specified ).

  HTH,
  Christoph Schittko

  ----- Original Message -----
  From: "Axel Heitland" <[EMAIL PROTECTED]>
  To: <[EMAIL PROTECTED]>
  Sent: Saturday, August 17, 2002 4:49 PM
  Subject: Re: [ADVANCED-DOTNET] using system.collections in .net


  Have a look at IDictionary ...

  HTH
          Axel

  -----Original Message-----
  From: Don & Linda [mailto:[EMAIL PROTECTED]]
  Sent: Freitag, 16. August 2002 21:36
  To: [EMAIL PROTECTED]
  Subject: [ADVANCED-DOTNET] using system.collections in .net


  I am trying to implement my own collection class for an object in VB by
  inheriting from System.Collection.CollectionsBase.  However, I would
  like to use a key to insert my objects into the collection.  It looks
  like the add method in the collectionsbase class has only the object as
  an argument.

  Is there another class that I can inherit from that does what I need it
  to do.

  Ideally, I want to be able to do something like I used to be able to do
  in vb6:

  Public Sub Add(objItemToAdd As OrderDetail, _
                 Optional Key As String = "", _
      mCollection.Add objItemToAdd, Key
  End Sub

  Thanks in advance,

  Linda

  You can read messages from the Advanced DOTNET archive, unsubscribe from
  Advanced DOTNET, or
  subscribe to other DevelopMentor lists at http://discuss.develop.com.

  You can read messages from the Advanced DOTNET archive, unsubscribe from
  Advanced DOTNET, or
  subscribe to other DevelopMentor lists at http://discuss.develop.com.

  You can read messages from the Advanced DOTNET archive, unsubscribe from
  Advanced DOTNET, or
  subscribe to other DevelopMentor lists at http://discuss.develop.com.

  You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
  subscribe to other DevelopMentor lists at http://discuss.develop.com.


You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to