Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LINQ All returns True if the size of the collection is 0. #110433

Closed
EvgenyMarchuk opened this issue Dec 5, 2024 · 2 comments
Closed

LINQ All returns True if the size of the collection is 0. #110433

EvgenyMarchuk opened this issue Dec 5, 2024 · 2 comments

Comments

@EvgenyMarchuk
Copy link

Description

I'm getting true for the zero size collection, using LINQ All to check that all items have a value

Reproduction Steps

var list = new List<string>();
var isTrue = list.All(x => x == "a");
Console.WriteLine(isTrue);

Expected behavior

False

Actual behavior

True

Regression?

No response

Known Workarounds

No response

Configuration

.net8.0.404
Win10, x64

Other information

If I'm not mistaken, the same is in .net9

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 5, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.

@EvgenyMarchuk EvgenyMarchuk changed the title LINQ All return True if the cooliction size is 0 LINQ All returns True if the size of the collection is 0. Dec 5, 2024
@stephentoub
Copy link
Member

stephentoub commented Dec 5, 2024

Thanks, but this is by design. Every item meets the criteria. There just aren't any items.

Per the docs:
"true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false."

@stephentoub stephentoub closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants