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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:21:59+00:00 2026-05-22T01:21:59+00:00

I am using the powercollections library from http://powercollections.codeplex.com/ The first test passes, however the

  • 0

I am using the powercollections library from http://powercollections.codeplex.com/

The first test passes, however the second test fails. I wouldn’t expect Remove to remove all items from the dictionary if a value was not found.

Is this an issue or am I misunderstanding how Remove functions ?

[Test]
public void passing_test()
{
    var classes = new MultiDictionary<string, object>(false);
    classes.Add("class", "class_name1");
    classes.Add("class", "class_name2");
    classes.Remove("class", "class_name2");

    Assert.AreEqual(1, classes.Count);
}

[Test]
public void failing_test()
{
    var classes = new MultiDictionary<string, object>(false);
    classes.Add("class", "class_name1");
    classes.Remove("class", "class_name2");

    Assert.AreEqual(1, classes.Count);
}
  • 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-05-22T01:22:00+00:00Added an answer on May 22, 2026 at 1:22 am

    It actually looks like a bug in the code:

            /// <summary>
            /// Removes a given value from the values associated with a key. If the
            /// last value is removed from a key, the key is removed also.
            /// </summary>
            /// <param name="key">A key to remove a value from.</param>
            /// <param name="value">The value to remove.</param>
            /// <returns>True if <paramref name="value"/> was associated with <paramref name="key"/> (and was
            /// therefore removed). False if <paramref name="value"/> was not associated with <paramref name="key"/>.</returns>
            public sealed override bool Remove(TKey key, TValue value)
            {
                KeyAndValues keyValues = new KeyAndValues(key);
                KeyAndValues existing;
    
                if (hash.Find(keyValues, false, out existing)) {
                    // There is an item in the hash table equal to this key. Find the value.
                    int existingCount = existing.Count;
                    int valueHash = Util.GetHashCode(value, valueEqualityComparer);
                    int indexFound = -1;
                    for (int i = 0; i < existingCount; ++i) {
                        if (Util.GetHashCode(existing.Values[i], valueEqualityComparer) == valueHash &&
                            valueEqualityComparer.Equals(existing.Values[i], value)) 
                        {
                            // Found an equal existing value
                            indexFound = i;
                        }
                    }
    
                    if (existingCount == 1) {
                        // Removing the last value. Remove the key.
                        hash.Delete(existing, out keyValues);
                        return true;
                    }
    

    Notice how they are checking for existingCount == 1? Although the values you entered differ, there is no code to check whether the index was found in the search prior to the hash.Delete call. The correct way to fix this would be to do something like:

                if (existingCount == 1 && indexFound != -1) {
                    // Removing the last value. Remove the key.
                    hash.Delete(existing, out keyValues);
                    return true;
                }
    

    Here’s the full source: http://powercollections.codeplex.com/SourceControl/changeset/view/6259#71508

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

Sidebar

Related Questions

Iv'e downloaded a C# interval tree collection class class from here http://intervaltree.codeplex.com/SourceControl/list/changesets -> Right
Using Google Maps InfoBox - http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html Currently the map will scroll - pan control
Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
I am serializing , a MultiDictionary<String,Object> http://powercollections.codeplex.com/ to json . It has 618 elements
Using jQuery rotate http://code.google.com/p/jqueryrotate/wiki/Examples to animate an object from 0 degrees to 40 degrees
Using Visual C++ 2008. First time, I'm experimenting in crossing over from C# and
Using mercurial, I've run into an odd problem where a line from one committer
Using php/html, I want to retrieve email addresses (plus other information) from MySQL and
(Using MVC 2) From inside my controller action, I need to display the url:
Using Java, how can I extract all the links from a given web page?

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.