The Artima Developer Community
Sponsored Link

.NET Buzz Forum
An update on iterating HybridDictionary objects

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jon Box

Posts: 244
Nickname: jonbox
Registered: Dec, 2003

Jon Box is a .NET Developer and Regional Director.
An update on iterating HybridDictionary objects Posted: Jan 25, 2004 2:51 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Jon Box.
Original Post: An update on iterating HybridDictionary objects
Feed Title: Jon Box's Weblog
Feed URL: http://radio-weblogs.com/0126569/rss.xml
Feed Description: This is a log of my findings and amusements with .NET. I also present information on my presentations and others that I see.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Jon Box
Latest Posts From Jon Box's Weblog

Advertisement

A couple of weeks ago, I posted a new learning “Ever depended on the order of elements in a HybridDictionary?”.  It was then pointed out to me by Steve Maine that the typical hashtable implementation shouldn’t return a ordered list of any type.  After some skillful assistance by Dan Fox, he found that one can get a sorted return if integer keys are used instead of string keys.  During my learning lesson, I did use integer keys (which works).  But when I typed up an example for the blog using string keys, I assumed that this would work the same way.  It does not.  Here are the results of the sample below:

 

String keys

2 = 915793710

3 = 306194301

1 = 821758039

6 = 2073203188

7 = 127676433

4 = 836905414

5 = 218444477

8 = 1218696123

9 = 975467952

10 = 610848541

 

Integer keys

10 = 610848541

9 = 975467952

8 = 1218696123

7 = 127676433

6 = 2073203188

5 = 218444477

4 = 836905414

3 = 306194301

2 = 915793710

1 = 821758039

 

Here is the sample:

 

    Sub Main(ByVal args As String())

        Dim r As New Random(13123123)

        Dim c As New HybridDictionary

        Dim i As Integer

 

        If args.Length = 0 Then

            Console.WriteLine("Cmd Line Args: 0-string key, 1-integer key")

        Else

            'Show key type

            If args(0) = "0" Then

                Console.WriteLine("String keys")

            Else

                Console.WriteLine("Integer keys")

            End If

 

            'Add to dictionary

            For i = 1 To 50

                If args(0) = "0" Then

                    c.Add(CStr(i), r.Next)

                Else

                    c.Add(i, r.Next)

                End If

            Next

        End If

 

        'Print out list

        Dim e As DictionaryEntry

        For Each e In c

            Console.WriteLine(e.Key & " = " & e.Value)

        Next

 

    End Sub

 

Read: An update on iterating HybridDictionary objects

Topic: Authorization and Profile Application Block Previous Topic   Next Topic Topic: Express yourself - XML Schema versioning, first blood

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use