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 8197171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:41:15+00:00 2026-06-07T05:41:15+00:00

I have problem with Dictionary(buzzCompaignsPerUserIntersets) . I have dictionary (key = stringand value =

  • 0

I have problem with Dictionary(buzzCompaignsPerUserIntersets). I have dictionary (key = stringand value = ICollection), I want to remove from value of each key, campaign which verify condition here is the code that I used:

buzzCompaignsPerUserIntersets = Dictionary<string, ICollection<Buzzcompaign> ;

foreach(var dic_compaign in buzzCompaignsPerUserIntersets)
{
    
     var listCompaign = buzzCompaignsPerUserIntersets[dic_compaign.Key];
     for (int i = 0; i < listCompaign.Count(); i++)
     {
         if (listCompaign.ElementAt(i).MayaMembership.MayaProfile.MayaProfileId == profile_id)
                         buzzCompaignsPerUserIntersets[dic_compaign.Key].Remove(listCompaign.ElementAt(i));         
      }                
}

with this code I have a strange result because I iterate over a dictionary from which I remove elements.

  • 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-07T05:41:15+00:00Added an answer on June 7, 2026 at 5:41 am

    The use of ElementAt(i) is not the ideal way to get a particular item and will perform poorly. Its usage suggests that you want a collection with an indexer, such as IList<T>.

    Using your current setup, you could use this approach:

    foreach(var key in buzzCompaignsPerUserIntersets.Keys)
    {
         var list = buzzCompaignsPerUserIntersets[key];
         var query = list.Where(o => o.MayaMembership
                                      .MayaProfile.MayaProfileId == profile_id)
                         .ToArray();
         foreach (var item in query)
         {
             list.Remove(item);
         }
    }
    

    Alternately, if you can change the ICollection<T> to an IList<T> you could use the indexer and the RemoveAt method. That would look like this:

    foreach(var key in buzzCompaignsPerUserIntersets.Keys)
    {
         var list = buzzCompaignsPerUserIntersets[key];
         for (int i = list.Count - 1; i >= 0; i--)
         {
             if (list[i].MayaMembership.MayaProfile.MayaProfileId == profile_id)
             {
                 list.RemoveAt(i);
             }
         }
    }
    

    A List<T> would let you use the RemoveAll method. If you’re interested in how that works take a look at my answer to another question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting problem, which is a function that returns a Dictionary<String,HashSet<String>> .
I have a simple text dictionary file, which contains words, separated by ';'.My problem
I have have a problem loading and accessing data from a value object in
I have a problem when trying to retrieve values from an array. I want
I have a problem. I want to make a dictionary that translates english words
I have a simple problem that i cannot solve. I have a dictionary: aa
I have problem with UIWebView delay when the load image from url. In my
I have a problem regarding multithreading and inserting an item to an Dictionary. The
I have a problem converting a File Blob comming from a Webservice to an
The problem: I have Dictionary<String, String> that I need an alias to, but I

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.