You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Users of Enumerable.TryGetNonEnumeratedCount() may expect the API to return true for a collection that only implements IReadOnlyCollection<T>. Instead, it returns false.
Reproduction Steps
create a new .NET 6 console app and run this code:
using System.Collections;
Console.WriteLine(Enumerable.TryGetNonEnumeratedCount(new A(), out _));
class A : IReadOnlyCollection<int>
{
public int Count => 0;
public IEnumerator<int> GetEnumerator()
{
yield break;
}
IEnumerator IEnumerable.GetEnumerator() =>
GetEnumerator();
}
Expected behavior
True is written to the console, indicating the collection was able to return a count sans enumeration.
Actual behavior
False is written to the console, indicating the collection was not able to return a count sans enumeration.
Regression?
No, this is a new API.
Known Workarounds
Test the collection size manually.
Configuration
No response
Other information
If this was a conscious decision, feel free to close this issue.
The text was updated successfully, but these errors were encountered:
Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.
Issue Details
Description
Users of Enumerable.TryGetNonEnumeratedCount() may expect the API to return true for a collection that only implements IReadOnlyCollection. Instead, it returns false.
Reproduction Steps
create a new .NET 6 console app and run this code:
using System.Collections;
Console.WriteLine(Enumerable.TryGetNonEnumeratedCount(new A(), out _));
class A : IReadOnlyCollection<int>
{
public int Count => 0;
public IEnumerator<int> GetEnumerator()
{
yield break;
}
IEnumerator IEnumerable.GetEnumerator() =>
GetEnumerator();
}
Expected behavior
True is written to the console, indicating the collection was able to return a count sans enumeration.
Actual behavior
False is written to the console, indicating the collection was not able to return a count sans enumeration.
Regression?
No, this is a new API.
Known Workarounds
Test the collection size manually.
Configuration
No response
Other information
If this was a conscious decision, feel free to close this issue.
Description
Users of Enumerable.TryGetNonEnumeratedCount() may expect the API to return true for a collection that only implements
IReadOnlyCollection<T>
. Instead, it returns false.Reproduction Steps
create a new .NET 6 console app and run this code:
Expected behavior
True
is written to the console, indicating the collection was able to return a count sans enumeration.Actual behavior
False
is written to the console, indicating the collection was not able to return a count sans enumeration.Regression?
No, this is a new API.
Known Workarounds
Test the collection size manually.
Configuration
No response
Other information
If this was a conscious decision, feel free to close this issue.
The text was updated successfully, but these errors were encountered: