473,396 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with SortedList

I am trying to make a SortedList using the following code:

Dim Poems As New SortedList(47)

Dim poemfiles As String() =
System.IO.Directory.GetFiles(Server.MapPath("poetr y/poems/"))

For Each poemfile As String In poemfiles

Poems.Add(System.IO.File.OpenText(poemfile).ReadLi ne(), poemfile)

Next


My application makes it through all this code fine, and I have tested that
both parameters in the Poems.Add() method are Strings. However, when I try
to access the SortedList I recieve an error about the IComparer. I use the
following expression inside a loop to attempt to access it (j is the loop
control variable):

CStr(CType(Global.Poems(j), DictionaryEntry).Key)
Because I am somewhat unfamiliar with the IComparer class and the help files
didn't seem to be of much help, could someone tell me what I am doing wrong?
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
1 1260
Try looping through it with:
For Each entry As DictionaryEntry In poems
Dim key As String = CStr(entry.Key)
Dim value As String = CStr(entry.Value)
Next

Also note that you aren't closing your openfile handlers...

For Each file As String In
IO.Directory.GetFiles("C:\karl\2005\HtmlClassGener ator\HtmlClassGenerator",
"*.cs")
Dim sr As StreamReader = IO.File.OpenText(file)
poems.Add(sr.ReadLine(), file)
sr.Close()
Next

AND that if two files start with the same line, you'll get an exception
because you can't add entries with the same key...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:u$**************@tk2msftngp13.phx.gbl...
I am trying to make a SortedList using the following code:

Dim Poems As New SortedList(47)

Dim poemfiles As String() =
System.IO.Directory.GetFiles(Server.MapPath("poetr y/poems/"))

For Each poemfile As String In poemfiles

Poems.Add(System.IO.File.OpenText(poemfile).ReadLi ne(), poemfile)

Next


My application makes it through all this code fine, and I have tested that
both parameters in the Poems.Add() method are Strings. However, when I try
to access the SortedList I recieve an error about the IComparer. I use the
following expression inside a loop to attempt to access it (j is the loop
control variable):

CStr(CType(Global.Poems(j), DictionaryEntry).Key)
Because I am somewhat unfamiliar with the IComparer class and the help
files didn't seem to be of much help, could someone tell me what I am
doing wrong? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael C | last post by:
Hi all, I'm using a SortedList to store data, and want the keys to be compared in case insensitive order, so that mySList is the same as mySList
2
by: Pekka | last post by:
Could somebody say why the piece of code below does not work? My purpose is to renumber keys in a SortedList (after removal of an item) so that the keys would always contain an unbroken sequence of...
2
by: Curious | last post by:
Hi, I am using SortedList, but I am having problems with indexing. SortedList x = new SortedList(); x.Add(0, "zero"); x.Add(1, "one"); x.Add(3, "three"); Console.WriteLine(x.ToString());
4
by: john conwell | last post by:
So you pass in the Key and it returns the array index of the key. but you cant do array index lookups. the indexer of the sortedlist does a binary search based on the key. So whats the pointof...
2
by: Prez | last post by:
I started writing .net code yesterday and I am grasping it well enough. I have a few questions about SortedLists. I am using managed C++ if that makes any difference. Of the examples I...
4
by: SHEBERT | last post by:
Here is an example of a SortedList that works as a datasource to the ComboBox and a generic SortedList<that does not works as a datasource to the ComboBox. Why? If I use List and generic List<>,...
4
by: sck10 | last post by:
Hello, I have a method in my codefile that builds a sorted list (see CodeFile). I am trying to create a class that does the same thing (see App_Code). CodeFile...
4
by: aeshiels | last post by:
Hello, I have a SortedList defined as... SortedList<CUser, CUseruserList = new SortedList<CUser, CUser>(); ....and which to copy it to another sorted list SortedList<CUser,...
1
by: raylopez99 | last post by:
I seem to get name collision between the Generic collection SortedList and C++.NET Framework collection SortedList. How to resolve? Here are the libraries that seem to clash:...
1
by: asem0525 | last post by:
Hello guys, I have this kind of problem: first, the textBox tbISBN has a value that is read from the text file, but then after pressing the "Clear" button, it should be realized, and when I enter...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.