8943

int[] array=null; foreach(int iin array??Enumerable.Empty()) { System.Console.WriteLine(string.Format(“{0}”, i)); }

and

int[] returnArray=Do.Something()??newint[]{};

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

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?