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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:06:40+00:00 2026-06-09T14:06:40+00:00

Back in time when .NET Reflector was free I used it to gasp into

  • 0

Back in time when .NET Reflector was free I used it to gasp into the .NET framework code. It came to my attention that most collections in .NET 2.0 (I believe this is applicable for current versions too) use the following mechanism to recognize collection modifications during loops:

public class SomeCollection<T>
{
    internal int version = 0;

    // code skipped for brevity

    public void Add(T item)
    {
        version++;

        // add item logic ...
    }

    public IEnumerator<T> GetEnumerator()
    {
         return new SomeCollectionEnumerator<T>(this);
    }
}

public class SomeCollectionEnumerator<T> : IEnumerator<T>
{
     private SomeCollection<T> collection;
     private int version;

     public SomeCollectionEnumerator(SomeCollection<T> collection)
     {
         this.version = collection.version;
         this.collection = collection;
     }

     public bool MoveNext()
     {
         if (this.version != this.collection.version)
         {
             // collection was modified while iterated over
             throw SomeException(...);
         }
         // iteration logic here...
     }
}

Now imagine the hypothetical case of a long running application (a heavily used web service that must have minimal downtime and should be stable and reliable) that keeps a given collection instance (one of the built-in collection types in .NET framework) in memory for as long as it runs. The collection gets modified frequently enough so that int.MaxValue modifications are possible to happen. Is there a risk that the version++ line in every modification method of the collection throws an overflow exception (assuming the overflow checks are not globally disabled).

I must admit that I have weak memories of the details of the reflected code, but I do not remember usage of unckecked blocks around version++ operations. Does this mean built-in collection types in .NET are not suitable for the purpose of such long-time running application scenario? Just out of curiosity, has someone encountered a real-life scenario where this could actually happen?

  • 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-09T14:06:42+00:00Added an answer on June 9, 2026 at 2:06 pm

    No, because the c# compiler makes integer arithmetic unchecked by default. (This includes the compiled BCL.)

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

Sidebar

Related Questions

Every time I come back the data to the user, I see that .NET
I ran across a small framework some time back that someone put together for
Back in 2006 I've created a web site using asp.net 2.0. At that time,
.Net framework contains a great class named Convert that allows conversion between simple types,
I have been working with .Net since VS2002 and since then any time that
I made a game in VB .Net that uses tcp and sends messages back
I'm a .NET developer but I like JAVA so in my free time I
I asked a question CSS Gradients with little content some time back I came
I'm a Java/.NET developer but on my spare time I've started looking into WordPress
I've been coding with .NET since it came out of beta. That's a long

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.