8943
int[] array=null; foreach(int iin array??Enumerable.Empty()) { System.Console.WriteLine(string.Format(“{0}”, i)); }
and
int[] returnArray=Do.Something()??newint[]{};
and
…??newint[0]
In a NotifyCollectionChangedEventHandler I wanted to apply the Enumerable.Empty like so:
foreach(DrawingPoint drawingPointin e.OldItems??Enumerable.Empty()) this.RemovePointMarker(drawingPoint);
Note: OldItems is of the type IList
And it gives me:
Operator ‘??’ cannot be applied to operands of type ‘System.Collections.IList’ and System.Collections.Generic.IEnumerable
However
foreach(DrawingPoint drawingPointin e.OldItems??newint[0])
and
foreach(DrawingPoint drawingPointin e.OldItems??newint[]{})
works just fine.
Why is that?
Why does IList ?? T[] work but IList ?? IEnumerable doesn’t?