Skip to content

EnsureCapacity() on List<> increments the version #82455

Closed

Description

@mikernet

Description

Apparent oversight: Setting Capacity or calling TrimExcess() on List<> does not increment the version but calling EnsureCapacity(int) does.

Reproduction Steps

var x = new List<int>();
var e = x.GetEnumerator();
x.EnsureCapacity(10);
e.MoveNext(); // collection modified exception due to version increment

Expected behavior

Calling EnsureCapacity should not increment the version.

Actual behavior

Calling EnsureCapacity increments the version.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. ghost added
    untriaged
    on Feb 21, 2023
  2. hez2010 commented on Feb 21, 2023

    @hez2010
    Contributor

    See #81523
    We may remove the check completely in the future.

  3. mikernet commented on Feb 22, 2023

    @mikernet
    ContributorAuthor

    Yeah, I mentioned this in that discussion as well but wanted to create an issue to track this specifically in case a decision is made to keep the version checks.

  4. removed
    untriaged
    on Feb 22, 2023
  5. added this to the Future milestone on Feb 22, 2023
  6. ghost added
    in-pr
    on Feb 22, 2023
  7. ghost removed
    in-pr
    on Feb 23, 2023
  8. ghost locked as resolved and limited conversation to collaborators on Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions