search
Japanese Chinese Nederlands Espanol Italiano Deutsch Francais Twitter Rss Feeds
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

Web ProgrammingArticlesForumsFAQs
JavaScript
ASP
ASP.NET
Web Services

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Operating SystemsArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

View Other Visual Studio .NET Posts   Ask New Question 
I get negative index in array list
mostafa hamdy posted at Thursday, November 20, 2008 6:08 AM

hello all

I use asp.net 2 and I have some problem with array list , I have some array contains some objects and when I use the Binary seach method of the array list I get negative index althogh this object already exist in the array list the code I wrote is as the following ,please if any body can help me or can tell me about some URL can help me in solving this problem please send me

ArrayList arrOverTime = GetLengthOfOverTimePeriods(dtEmployeeOverTime);

int Index = 0;

while (DateTime.Parse(DateTime.Parse(MonthStartDay).ToShortDateString()) <= DateTime.Parse(DateTime.Parse(MonthEndDay).ToShortDateString()))

{

//compare every day in the month , is it in the arrovertime

object objDate = new object();

objDate = MonthStartDay;

Index = arrOverTime.BinarySearch(objDate);//is + if item exit in the array or - if not exit

if (Index < 0)

// in case the index is negative it means that this day is not in the over time period so update its record if any, with the new time rule

{

//updat the current month records with the new time rule

objCheckInOut.UpdateEmployeeCheckInOutRecordForOverTime(ContactID, DateTime.Parse(MonthStartDay), DateTime.Parse(DateTime.Parse(MonthStartDay).ToShortDateString()+" "+"23:59:59.000"), int.Parse(ddlTimeRule.SelectedValue));

}

MonthStartDay = DateTime.Parse(MonthStartDay).AddDays(1).ToShortDateString();

}

regards

Mostafa


 
  re
Web star replied to mostafa hamdy at Thursday, November 20, 2008 6:16 AM

The BinarySearch member of the ArrayList was very useful for me. This member returns the zero-based index of a specific element in the sorted ArrayList or a portion of it, using a binary search algorithm.

int myIndex=myList.BinarySearch( 3 );

That's it..  The ArrayList class is much more fun than this. See documentation for more details.

http://www.c-sharpcorner.com/UploadFile/mahesh/b_search11262005012607AM/b_search.aspx

http://msdn.microsoft.com/en-us/library/system.collections.arraylist.binarysearch.aspx

bytes.com/forum/thread231456.html