-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Closed
Copy link
Description
Description
runtime/src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.SpeedOpt.cs
Lines 69 to 83 in ea4bea9
| public override TSource? TryGetElementAt(int index, out bool found) | |
| { | |
| TSource? item = _source.TryGetElementAt(index, out found); | |
| if (found) | |
| { | |
| return item; | |
| } | |
| if (index == 0) | |
| { | |
| found = true; | |
| } | |
| return _default; | |
| } |
Iterator<TSource>.TryGetElementAt should return default(TSource) when not found but here it returns _default.
Reproduction Steps
int result = Array.Empty<int>().DefaultIfEmpty(1).ElementAtOrDefault(1);
Console.WriteLine(result);Expected behavior
Outputs 0.
Actual behavior
Outputs 1.
Regression?
The bug was introduced in .NET 9.
Known Workarounds
No response
Configuration
No response
Other information
No response
Copilot