473,761 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need some C# ArrayList For loop help!

3 New Member
I have a loop that looks like this

Expand|Select|Wrap|Line Numbers
  1. int i;
  2. for (i = 0; i < FriendsArray.Count; i++)
  3.  
  4. {
  5.  
  6.     MessageBox.Show("Im in the loop " + key);
  7.  
  8.     if (FriendsArray.BinarySearch(key) >= 0)
  9.     {
  10.          MessageBox.Show("Key Found " + key);
  11.     }
  12.     else
  13.     {
  14.         FriendsArray.Add(key);
  15.         tabAdded = tabs.Add(key, AVName);
  16.         MessageBox.Show("Key Not Found " + key);
  17.     }
  18. }
  19.  
now you can all probobaly see something seriously wrong with that. all i want todo is know if there is a key in my ArrayList, if there is then do nothing. but if there is not then add a key. add my tab. and show the msg it was not found. i cant figure this out for the life of me <im new to C# but picking it up fast>
Thank you in advance :)
Aug 14 '08 #1
5 1305
r035198x
13,262 MVP
I don't see anything wrong with that as long as your array is sorted and each of the elements in it implement the IComparable interface
Aug 14 '08 #2
pootle
68 New Member
Well I do not see the point of the loop. It will do the same thing each time. Why do you use the loop?
Aug 14 '08 #3
Daten
3 New Member
im used to working in an event based scripting language and that would be ho wi had to search a list. i know C# is different and there may be another way but im not sure . i think i know why this loop does not work. my array is always empty
Aug 14 '08 #4
r035198x
13,262 MVP
im used to working in an event based scripting language and that would be ho wi had to search a list. i know C# is different and there may be another way but im not sure . i think i know why this loop does not work. my array is always empty
The BinarySearch method you called also does the looping for you. There is no need to loop through the array if you are using it.
Aug 14 '08 #5
Daten
3 New Member
ahh i see, thank you :) i got it partialy working now :D
Aug 14 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
464
by: Stephen | last post by:
I have been getting on well with help from this forum trying to create an array list and work with it. Everything is working fine apart from displaying my array list items into the labels in my asp table. The asp table has numerous rows and each row has a label item within it. Im finding it impossible to get something to work which adds the newest item in the array list to the next row in the asp table. the first time the button is...
10
3593
by: Eric | last post by:
I'm looking at this page in the MSDN right here: ms-help://MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemcollectionsarraylist classsynchronizedtopic2.htm (or online here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsicollectionclasssyncroottopic.asp) And I'm interested in locking an ArrayList during the entire enumeration, as shown in the example code. My problem is that I'm STILL...
5
2140
by: Tim | last post by:
Hi, I am creating a printing engine and I am cycling though my recordset. Each item gets added to an ArrayList. Once there are more items that will fit on the page I add the item ArrayList to a pages ArrayList. Seems pretty simple so far. However, when I clear the items ArrayList it clears everything. What I am trying to do is add a page worth of items to the pages ArrayList, clear it and then create another page worth of items etc...
6
5387
by: gane kol | last post by:
Hi, I have a code that creates a datatable from an arraylist, but i am getting an error in casting in for (int intRow = 0; intRow < alLCPlist.Count; intRow++) { DataRow drow = dtLCPack.NewRow(); int intColCount = dtLCPack.Columns.Count; ArrayList arrlRow = (ArrayList)alLCPlist; <== Specified cast
4
1282
by: Mike | last post by:
I have declared two classes. The first class has 4 private variables. Each has a property defined. I'm calling a readfile sub from a second class. The second class also has an Arraylist property. I sub readfile and dim a new object (inside a loop) of the first class and pass the four fields to each property of the first class until the EOF. Within this loop I want to add each object of the first class into the Array list of the...
2
5878
by: Anchor | last post by:
Hi All, I was hoping someone could help me out. I am new to VB.NET and I don't know the language too well. I am trying to add an object instance of a class to an array like in the code snipet below. I run through the For Each loop 5 times and I place a reference to the object in an ArrayList. Once I skip out of the loop block I expect to have 5 different instances of that class in the ArrayList. However, instead I have 5 instances of...
19
2461
by: Derek Martin | last post by:
Hi there, I have been playing with sorting my arraylist and having some troubles. Maybe just going about it wrong. My arraylist contains objects and one of the members of the object is 'name.' I would like to sort the arraylist based on object.name - is that possible? Thanks! Derek
13
2851
by: David | last post by:
Hi all, I have a singleton ienumerable that collects data from a database. I have listed the code below. It has the usual methods of current, move and reset. I need to go to a certain position or set filters or many other things and I don't know how to do this. I have just learned singleton AND ienumerable, so miraculously got this to work so far. I could do with a bit of help to go further with it. If need by, I may have to change the...
6
3140
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it to the client. Before adding data to the arraylist, I check if the depth of the arraylist is longer than iMaxQueueDepth, and if it is, I clear the arraylist. Is it possible that while I am clearing the arraylist, the ThreadMain at the same time...
32
3873
by: falconsx23 | last post by:
I am making a game called Set, it is a card game: here is a brief description of the rules: The game of Set is played with 81 cards, each of which has 4 properties (number, pattern, color and shape). The number of objects is 1, 2, or 3. The 3 possible patterns are solid, striped, and open. The 3 possible colors are red, green, and purple. The 3 possible shapes are diamond, squiggle, and oval. The 81 cards comprise all possible combinations...
0
9377
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
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
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
9811
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
8814
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
7358
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
6640
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();...
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
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.