I searched all over the internet to find an answer for this. I am looping through two lists (list1 and list2) with nested for loops and removing duplicate records in first list based on three criteria. If all records in these two lists match each other, I get an out of bounds error. I assume it happens when I remove all the items from the first list, and when it finally reduces to 0, and does not have any records to loop through, but putting an if statement to check the count of the first list (if inbox_emails_filtered_contacts.Count > 0) does not help either. Please let me know if any of you can tell me why this errors out.
Outlook Add-in in C#.net
for (int i = 0; i < list1.Count; i++)
{
for (int j = 0; j < list2.Count; j++)
{
if (list1.Count > 0)
{
if ((list1[i].username == registered_user)
&& (list1[i].from_email.ToLower() == list2[j].from_email.ToLower())
&& (list1[i].email_subject == list2[j].email_subject)
&& (list1[i].email_timestamp.ToLongDateString() == list2[j].email_timestamp.ToLongDateString()))
{
//Remove the duplicate email from inbox_emails_filtered_contacts
list1.RemoveAt(i);
}
}
}
}