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

  • Home
  • SEARCH
  • 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 647711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:45:08+00:00 2026-05-13T21:45:08+00:00

The .NET Framework contains since version 3.0 the ObservableCollection<T> , but why isn´t there

  • 0

The .NET Framework contains since version 3.0 the ObservableCollection<T>, but why isn´t there a ObservableKeyedCollection<TKey, TValue>.

Okay i could implement my own collection by deriving from KeyedCollection<TKey,TValue> and implementing the INotifyCollectionChanged interface, but whouldn´t it be a good addition to the .NET Framework.

  • 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-13T21:45:09+00:00Added an answer on May 13, 2026 at 9:45 pm

    The reason that there is no ObservableKeyedCollection (or any other such type which is merely a combination of other generic types) is because ObservableCollection is generic, and that makes implementation of an “ObservableKeyedCollection” as easy as this:

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Collections.Specialized;
    
    public class DictionaryWatcher : ObservableCollection<KeyValuePair<string, object>>, IDisposable
    {
        private NotifyCollectionChangedEventHandler watcher;
        private bool watching = false;
    
        public DictionaryWatcher()
        {
            watcher = new NotifyCollectionChangedEventHandler( ReportChange );
            CollectionChanged += watcher;
            Watched = true;
        }
    
        public bool Watched
        {
            get
            {
                return watching;
            }
    
            set
            {
                if (watching)
                {
                    lock (this)
                    {
                        CollectionChanged -= watcher;
                        watching = false;
                    }
                }
            }
        }
    
    public void Dispose()
    {
        Dispose( true );
        GC.SuppressFinalize( this );
    }
    
        public void Initialize()
        {
            this.Add( new KeyValuePair<string, object>( "First", 1 ) );
            this.Add( new KeyValuePair<string, object>( "Second", 2 ) );
            this.Add( new KeyValuePair<string, object>( "Turd", 3 ) );
            KeyValuePair<string, object> badValue = this[2];
            this.Remove( badValue );
        }
    
    protected virtual void Dispose( bool disposing )
    {
        if (disposing && Watched)
        {
            Watched = false;
        }
    }
    
        private void ReportChange( object sender, NotifyCollectionChangedEventArgs e )
        {
            Console.WriteLine( "Change made: {0}", e.Action );
        }
    }
    

    While that is certainly not a one-liner program, most of it is boilerplate. Most importantly, it doesn’t re-implement the ObservableCollection as you were suggesting; instead it fully utilizes it.

    The reason that it “whouldn’t be a good addition to the .NET Framework” is because when there’s already one way to do something, creating another way to do it is a bad idea. The fewer ways there are to get some particular task done, the fewer ways there are to do it poorly. 8 )

    The tools are provided, it’s now all about how you use them.

    Hope that helps!

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

Sidebar

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.