This is more a design issue, which I guess, than a real mistake or rant. Interestingly, people think of the following behavior:
In .NET, when you want to effectively represent an empty IEnumerable, you can use Enumerable.Empty<MyType>()this to cache an empty enumerated instance. This is a good and free micro-optimization, I think it could help if I relied heavily.
However, what the implementation looks like:
public static IEnumerable<TResult> Empty<TResult>() {
return EmptyEnumerable<TResult>.Instance;
}
internal class EmptyEnumerable<TElement>
{
static volatile TElement[] instance;
public static IEnumerable<TElement> Instance {
get {
if (instance == null) instance = new TElement[0];
return instance;
}
}
}
I would expect the assignment to happen inside the lock, after another zero check, but that is not what happens.
, (.. , , , ) ?
?