ArrayList Insert and BinarySearch

G

Guest

H

In Delphi the Search method has Two return values. 1 Bool to indicate if it is found and 1 integer to return the possition
If the bool was false, the index was the possition where the item should come. This was easy to call insert

Is their a way I can do the same in arraylist? I have an arraylist that rarely changes, but I need the very fast indexing and iterating. I don't mind an insert being a little slower

BTW, is their a way I could access these newsgroups with Outlook express? This web interface is not very "me"

Kind regards

Alexander
 
S

Sherif ElMetainy

Hello

The BinarySearch method does what you want. See MSDN docs.

Yes you can access these newsgroups with Outlook Express. Add a news account
with news server msnews.microsoft.com

Best regards,
Sherif

Zanzibar said:
Hi

In Delphi the Search method has Two return values. 1 Bool to indicate if
it is found and 1 integer to return the possition.
If the bool was false, the index was the possition where the item should
come. This was easy to call insert.
Is their a way I can do the same in arraylist? I have an arraylist that
rarely changes, but I need the very fast indexing and iterating. I don't
mind an insert being a little slower.
BTW, is their a way I could access these newsgroups with Outlook express?
This web interface is not very "me".
 
A

Alexander Muylaert

Hi

thanks for the tip on outlook.

Aha :)

Console.WriteLine( "The object to search for ({0}) is not found. The next
larger object is at index {1}.", myObject, ~myIndex );

Has the ~ something to do with it?

Very hard to know if doesn't mention this somewhere.

Kind regards

Alexander
 
J

Jon Skeet [C# MVP]

Sherif ElMetainy said:
The BinarySearch method does what you want. See MSDN docs.

BinarySearch will only work if the ArrayList is sorted. IndexOf will
always work.
 
M

Mattias Sjögren

Console.WriteLine( "The object to search for ({0}) is not found. The next
larger object is at index {1}.", myObject, ~myIndex );

Has the ~ something to do with it?

The BinarySearch method is documented to return "a negative number,
which is the bitwise complement of the index of the next element that
is larger than value or, if there is no larger element, the bitwise
complement of Count" if the value isn't found.

~ is C#'s binary complement operator.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top