arraylist check if date in another array list [Resolved]

Posted by Surajemo under C# on 11/1/2012 | Points: 10 | Views : 1994 | Status : [Member] | Replies : 6
i have two array list (a) contains 10 dates another arraylist (b) contains 5 date

i want to check if that date which is present in array list (a) is it present in array list (b)
can anyone help me out with that please




Responses

Posted by: Naraayanan on: 11/2/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi,
try this Code
ArrayList list1 = new ArrayList(new DateTime[] { Convert.ToDateTime("2010-12-01"), Convert.ToDateTime("2010-12-11"), Convert.ToDateTime("2010-12-21") });

ArrayList list2 = new ArrayList(new DateTime[] { Convert.ToDateTime("2010-12-01"), Convert.ToDateTime("2010-12-15"), Convert.ToDateTime("2010-12-22") });
int CountofList1 = list1.Count;
int CountofList2 = list2.Count;
if (CountofList1 > CountofList2)
{
foreach (DateTime str in list1)
{
if (!list2.Contains(str))
{
MessageBox.Show(Convert.ToString(str));
}
}
}
else if (CountofList1 == CountofList2)
{
foreach (DateTime str in list2)
{
if (!list1.Contains(str))
{
MessageBox.Show(Convert.ToString(str));
}
}
}

else
{
foreach (DateTime str in list2)
{
if (!list1.Contains(str))
{
MessageBox.Show(Convert.ToString(str));
}
}
}


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Surajemo, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Surajemo on: 11/2/2012 [Member] Starter | Points: 25

Up
0
Down
dtMeetingdate.Sort(); //1st Arraylist
currentdata.Sort(); //2nd Arraylist
int bcount = dtMeetingdate.Count;
int fcount = currentdata.Count;
if (bcount > fcount)
{

foreach (var item1 in dtMeetingdate)
{
foreach (var item2 in currentdata)
{
if (item1.ToString() == item2.ToString())
{
return true;
}
}
}
}
else
{

foreach (var item1 in currentdata)
{
foreach (var item2 in dtMeetingdate)
{
if (item1.ToString() == item2.ToString())
{
return true;
}
}
}
}
i want to use arraylist1.containsin arraylist2 and then evaluate how do i do that

Surajemo, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Surajemo on: 11/2/2012 [Member] Starter | Points: 25

Up
0
Down
sir this will work but i want to avoid the number of loops

Surajemo, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Surajemo on: 11/3/2012 [Member] Starter | Points: 25

Up
0
Down
anyone can please tell me how do i avoid the number of loops

Surajemo, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Velkumar_In on: 12/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

You can directly use below method to check whether data is available in ArrayList
ArrayList.Contains("value");

Surajemo, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Surajemo on: 12/6/2012 [Member] Starter | Points: 25

Up
0
Down
Velkumar_In thanks for replying but i resolved it like this way


count = (from i in currdates.ToArray()
join j in dbdates.ToArray()
on i equals j
select new { ddate = i, cdate = j }).Count();

Surajemo, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response