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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:08:32+00:00 2026-05-23T00:08:32+00:00

Apologies if these are extremely basic questions, but let’s say I’m using the void

  • 0

Apologies if these are extremely basic questions, but let’s say I’m using the void Add(T item) function of BlockingCollection:

1) How would I override the Add function, i.e. if I want to add a check at the beginning and then call the base function, is this possible to do, and if so, would the code look something like this?

protected sealed class BlockingCollection<T> : IEnumerable<T>
    {
        protected override void Add(T item)
        {
            // do something here
            // call base blockingcollection add function, something like return base.Add(item)??
        }
    }

2) If instead of calling the base function, I wanted to actually modify the Add code, is there a way to get the underlying code for the Add function? Would I use something such as Reflection? If so, is there any way to get the underlying code without writing my own program and using reflection to get the method code (i.e. can I get the underlying method code within the Visual Studio IDE itself without having to write / compile / run code every time I want to get the underlying code of a method?)?

  • 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-23T00:08:33+00:00Added an answer on May 23, 2026 at 12:08 am

    IEnumerable doesn’t have an “Add” method; you’d have to implement your own. ICollection does, however!

    Also, because IEnumerable/ICollection are interfaces, not classes, there’s no existing implmementation for you to override. You have to do that part yourself.


    Edit for possible additional extra super duper correctness:

    If you’re trying to subclass BlockingCollection and you want to do some additional “stuff” before T is added via “Add”, you could do it like this:

    public class Foo<T> : BlockingCollection<T>
    {
        public new void Add(T item)
        {
            base.Add(item);
            base.Add(item);
        }
    }
    

    So, this extremely simple implementation will add anything you put into your Foo via “Add” twice.

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

Sidebar

Related Questions

Apologies if any of what I'm about to say makes no sense or overlooks
Apologies for the long post, but I wonder if I could get some more
Apologies in advance for the long-winded question. I'm really a database programmer, but have
Apologies for the vagueness of the question here but can someone point me to
I tried to find a similar question on SO but had no luck. Apologies
What's the difference between the following two pieces of HTML (apologies if there are
Apologies if I get the terminology wrong. How do I define a constraint in
I am just getting started with IoC containers so apologies if this is a
Good morning, Apologies for the newbie question. I'm just getting started with ASP.NET internationalization
Greetings, Apologies in advance that I have not researched this toughly enough to answer

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.