Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8277321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:39:43+00:00 2026-06-08T08:39:43+00:00

I searched all over the internet to find an answer for this. I am

  • 0

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);
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:39:44+00:00Added an answer on June 8, 2026 at 8:39 am

    here is an implementation of an Email class

    class Email:IComparable<Email>
    {
        private static int _Id;
    
        public Email()
        {
            Id = _Id++;
        }
    
        public int Id { get; private set; }
        public string UserName { get; set; }
        public string Body { get; set; }
        public string Subject { get; set; }
        public DateTime TimeStamp { get; set; }
    
        public override int GetHashCode()
        {
            return UserName.GetHashCode() ^ Body.GetHashCode() ^ Subject.GetHashCode();
        }
    
        public int CompareTo(Email other)
        {
            return GetHashCode().CompareTo(other.GetHashCode());
        }
    
        public override string ToString()
        {
            return String.Format("ID:{0} - {1}", Id, Subject);
        }
    
        public override bool Equals(object obj)
        {
            if (obj is Email)
                return CompareTo(obj as Email) == 0;
            return false;
        }
    
    }
    

    and 2 ways of getting the diff.

            var list1 = new List<Email>();
            var ran = new Random();
            for (int i = 0; i < 50; i++)
            {
                list1.Add(new Email() { Body = "Body " + i, Subject = "Subject " + i, UserName = "username " + i, TimeStamp = DateTime.UtcNow.AddMinutes(ran.Next(-360, 60)) });
            }
            var list2 =  new List<Email>();
    
            for (int i = 0; i < 50; i++)
            {
                if (i % 2 == 0)
                    list2.Add(new Email() { Body = "Body " + i, Subject = "Subject Modifed" + i, UserName = "username " + i, TimeStamp = DateTime.UtcNow.AddMinutes(ran.Next(-360, 60)) });
                else 
                    list2.Add(new Email() { Body = "Body " + i, Subject = "Subject " + i, UserName = "username " + i, TimeStamp = DateTime.UtcNow.AddMinutes(ran.Next(-360, 60)) });
    
            }
    
    
            foreach (var item in list2.Intersect<Email>(list1))
            {
                Console.WriteLine(item);
            }
    
            foreach (var item in list1)
            {
                for (int i = 0; i < list2.Count; i++)
                {
    
                    if (list2[i].Equals(item))
                    {
                        Console.WriteLine(item);
                        list2.RemoveAt(i);
                        break;
                    }
                }
            }
    
            Console.WriteLine(list2.Count);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've searched all over for an answer to this, but cannot find any clear
I've searched all over and couldn't find an answer to this seemingly common question,
I've searched all over the internet, but I can't find an answer to my
I searched all over the internet and this site and I can't figure this
This really puzzled for hours, I searched all over the internet, but got no
I've searched all over for an answer to this simple question, with no luck.
Last few days I searched all over the internet to solve this problem but
I have searched all over the internet trying to find example code in PHP
So I searched all over internet and in every single topic I found this
I tried this but colors is unknown (I searched all over internet amazingly not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.