I am trying to make a SortedList using the following code:
Dim Poems As New SortedList(47)
Dim poemfiles As String() =
System.IO.Direc tory.GetFiles(S erver.MapPath(" poetry/poems/"))
For Each poemfile As String In poemfiles
Poems.Add(Syste m.IO.File.OpenT ext(poemfile).R eadLine(), 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(Glob al.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********@hotm ail.com http://www.nathansokalski.com/ 1 1274
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.Valu e)
Next
Also note that you aren't closing your openfile handlers...
For Each file As String In
IO.Directory.Ge tFiles("C:\karl \2005\HtmlClass Generator\HtmlC lassGenerator",
"*.cs")
Dim sr As StreamReader = IO.File.OpenTex t(file)
poems.Add(sr.Re adLine(), 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********@hot mail.com> wrote in message
news:u$******** ******@tk2msftn gp13.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.Direc tory.GetFiles(S erver.MapPath(" poetry/poems/"))
For Each poemfile As String In poemfiles
Poems.Add(Syste m.IO.File.OpenT ext(poemfile).R eadLine(), 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(Glob al.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********@hotm ail.com http://www.nathansokalski.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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 integers starting
with 1. For some reason this is not the result.
IDictionaryEnumerator dictEnum = sortedList.GetEnumerator();
int i=1;
while ( dictEnum.MoveNext() ) {
DictionaryEntry de = (DictionaryEntry) dictEnum.Current;
|
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());
|
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 this method? is there a way
to return a array item based on the index?
|
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 have seen it looks like the Sorted List does not use
the ^ while other variables do use the ^. I have used the SortedList
with the ^ and gcnew and it seems to work fine. So the question is...
| |
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<>, both works.
private void Form1_Load(object sender, EventArgs e)
{
System.Collections.SortedList QA1 = new
System.Collections.SortedList();
|
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
===================================
public void PostSearch(string HRID)
{
SortedList PostSearchList = new SortedList();
|
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, CUseruserList2 = new SortedList<CUser,
|
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:
System::Collections::SortedList,
System::Collections::Generic::SortedList,
using namespace System::Collections;
using namespace System::Collections::Generic;
Below is a working version of the generic template SortedList, which
|
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 the new text into the textBox it should get the new text that I entered, but it keeps it's first value, even after the "Clear" button event.
Here is the code.
public partial class _Default : System.Web.UI.Page
{
private Book selectedBook;
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |