473,800 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how looping over a dictionary by loop for

I need to access to a dictionary by its index like a string array.
Dictionary<stri ng, stringtdmDx1 = new Dictionary<stri ng, string>();
for (int item = 0; item < tdmDx1.Count; item++) {

.... how access item by its index ???

}

Sam
Jun 27 '08 #1
3 1397
<sk*****@gmail. comwrote:
I need to access to a dictionary by its index like a string array.
Dictionary<stri ng, stringtdmDx1 = new Dictionary<stri ng, string>();
for (int item = 0; item < tdmDx1.Count; item++) {
.... how access item by its index ???
foreach (KeyValuePair<s tring, stringkv in tdmDx1)

Eq.
Jun 27 '08 #2
On Apr 27, 5:42*pm, skne...@gmail.c om wrote:
I need to access to a dictionary by its index like a string array.
Dictionary<stri ng, stringtdmDx1 = new Dictionary<stri ng, string>();
for (int item = 0; item < tdmDx1.Count; item++) {

* *.... how access item by its index ???

}

Sam
You can't because the Dictionary class is implemented with a hashtable
so the index doesn't make much sense. Let me ask you this...what
would you want the index value of 0 to mean? That might help us
determine what kind of collection best fits your needs.
Jun 27 '08 #3
Sam, Not sure why you need to loop thru a dictionary using index, but have
you had a look at wintellect's power collections
(http://www.wintellect.com/PowerCollections.aspx). The OrderedDictiona ry
might be what you are looking for.

Cheers!

"sk*****@gmail. com" wrote:
I need to access to a dictionary by its index like a string array.
Dictionary<stri ng, stringtdmDx1 = new Dictionary<stri ng, string>();
for (int item = 0; item < tdmDx1.Count; item++) {

.... how access item by its index ???

}

Sam
Jun 27 '08 #4

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

Similar topics

6
2518
by: Some Clown | last post by:
Greetings, I'm trying to figure out how to loop through a vector of strings, searching each item as I go for either a boolean condition or a "contains" test. So if my vector is called 'v' I need to test v.0 for a boolean condition, then test v.1 and put the results in a new string, etc. I've tried several methods, none of which have worked. I've also been looking through my shiny "The C++ Programming Language" guide, but that's not...
2
2577
by: Ivo | last post by:
Hi, I have an audio file (.mid or .wav or .mp3) in an object element: <object id="snd" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf. cab#Version=5,1,52,701" type="application/x-oleobject" width="282" height="53"> <param name="FileName" value="Tjaikovsky_-_The_sorcerers_apprentice.mid" /> <param name="loop" value="true" /> <... more presentational params...
45
7486
by: Trevor Best | last post by:
I did a test once using a looping variable, first dimmed as Integer, then as Long. I found the Integer was quicker at looping. I knew this to be true back in the 16 bit days where the CPU's (80286) word size was 16 bits same as an integer. Now with a 32 bit CPU I would have expected the long to be faster as it's the same size as the CPU's word size so wouldn't need sawing in half like a magician's assistant to calculate on like an...
2
8537
by: John McMonagle | last post by:
Say I have a dictionary like below: d = {(100,500):, (100,501):, (100,502):} Say I want to multiply all the values of the dictionary by 2: for key in d.keys(): d = map(lambda x: x*2, d.get(key)) Is there a better/faster/cleaner way to achieve this ?
6
1671
by: Justin Fancy | last post by:
Hi Everyone, I'm lookin for a very confusing loop (to me), to compare two files. Here it is. I have two arrays with paths stored in both. example: /en/aviation/you.htm. I need to search array two for all the paths in array 1. If it finds it, send it to array 3. Here's my code to send it to the array.
4
34163
by: O.B. | last post by:
I need the ability to parse through the values of a Dictionary and remove certain ones depending on their attribute values. In the example below, an InvalidOperationException is thrown in the foreach statement when the first item is removed from the Dictionary. From looking at Dictionary's methods, I couldn't find anything to create a copy of the Values before starting the foreach loop. Help? static void someTest() {
18
2979
by: Marko.Cain.23 | last post by:
Hi, I create a dictionary like this myDict = {} and I add entry like this: myDict = 1 but how can I empty the whole dictionary? Thank you.
11
2655
by: Dan Upton | last post by:
This might be more information than necessary, but it's the best way I can think of to describe the question without being too vague. The task: I have a list of processes (well, strings to execute said processes) and I want to, roughly, keep some number N running at a time. If one terminates, I want to start the next one in the list, or otherwise, just wait.
0
2082
by: Gary Herron | last post by:
Dan Upton wrote: Yes. Create a list of keys, and loop through it: pids = procs_dict.keys() for pid in pids: if procs_dict.poll() != None # do the counter updates del procs_dict Then the diction delete operation won't trip up the loop and its
0
9691
marktang
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...
0
9551
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,...
0
10276
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 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...
0
10035
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 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...
0
9090
agi2029
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...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
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...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.