2017-04-18 07:52:04 +08:00
|
|
|
## Enumerable.Empty<TResult> always returns cached instance
|
2017-04-06 04:52:19 +08:00
|
|
|
|
|
|
|
### Scope
|
|
|
|
Edge
|
|
|
|
|
|
|
|
### Version Introduced
|
|
|
|
4.5
|
|
|
|
|
|
|
|
### Source Analyzer Status
|
|
|
|
Available
|
|
|
|
|
|
|
|
### Change Description
|
|
|
|
|
2017-04-21 02:19:05 +08:00
|
|
|
Beginning in .NET 4.5,
|
|
|
|
<xref:System.Linq.Enumerable.Empty``1> always
|
|
|
|
returns a cached internal instance
|
|
|
|
<xref:System.Collections.Generic.IEnumerable`1>.
|
|
|
|
|
|
|
|
Previously, <xref:System.Linq.Enumerable.Empty``1>
|
|
|
|
would cache an empty
|
|
|
|
<xref:System.Collections.Generic.IEnumerable`1> at
|
|
|
|
the time the API was called, meaning that in some conditions in which
|
|
|
|
<xref:System.Linq.Enumerable.Empty``1> was called
|
|
|
|
rapidly and concurrently, different instances of the type could be returned for
|
|
|
|
different calls to the API.
|
2017-04-06 04:52:19 +08:00
|
|
|
|
|
|
|
- [ ] Quirked
|
|
|
|
- [ ] Build-time break
|
|
|
|
|
|
|
|
### Recommended Action
|
2017-04-21 02:19:05 +08:00
|
|
|
|
|
|
|
Because the previous behavior was non-deterministic, code is unlikely to depend
|
|
|
|
on it. However, in the unlikely case that empty enumerables are being compared
|
|
|
|
and expected to sometimes be unequal, explicit empty arrays should be created
|
|
|
|
(`new T[0]`) instead of using
|
|
|
|
<xref:System.Linq.Enumerable.Empty``1>.
|
2017-04-06 04:52:19 +08:00
|
|
|
|
|
|
|
### Affected APIs
|
|
|
|
* ```M:System.Linq.Enumerable.Empty``1```
|
|
|
|
|
|
|
|
### Category
|
|
|
|
LINQ
|
|
|
|
|
2017-04-18 07:52:04 +08:00
|
|
|
<!-- breaking change id: 42 -->
|