473,385 Members | 1,320 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,385 software developers and data experts.

Need some C# ArrayList For loop help!

3
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 1289
r035198x
13,262 8TB
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
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
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 8TB
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
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
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...
10
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:...
5
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...
6
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 =...
4
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...
2
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...
19
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...
13
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...
6
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...
32
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.