Null coalescing operator IList, Array, Enumerable.Empty in foreach
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
In this question I found the following:
int array = null;
foreach (int i in array ?? Enumerable.Empty<int>())
System.Console.WriteLine(string.Format("0", i));
and
int returnArray = Do.Something() ?? new int ;
and
... ?? new int[0]
In a NotifyCollectionChangedEventHandler
I wanted to apply the Enumerable.Empty
like so:
foreach (DrawingPoint drawingPoint in e.OldItems ?? Enumerable.Empty<DrawingPoint>())
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<WWSmartAufmassWpf.Data.DrawingPoint>
However
foreach (DrawingPoint drawingPoint in e.OldItems ?? new int[0])
and
foreach (DrawingPoint drawingPoint in e.OldItems ?? new int )
works just fine.
Why is that?
Why does IList ?? T
work but IList ?? IEnumerable<T>
doesn't?
c# .net collections null-coalescing-operator
add a comment |Â
up vote
6
down vote
favorite
In this question I found the following:
int array = null;
foreach (int i in array ?? Enumerable.Empty<int>())
System.Console.WriteLine(string.Format("0", i));
and
int returnArray = Do.Something() ?? new int ;
and
... ?? new int[0]
In a NotifyCollectionChangedEventHandler
I wanted to apply the Enumerable.Empty
like so:
foreach (DrawingPoint drawingPoint in e.OldItems ?? Enumerable.Empty<DrawingPoint>())
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<WWSmartAufmassWpf.Data.DrawingPoint>
However
foreach (DrawingPoint drawingPoint in e.OldItems ?? new int[0])
and
foreach (DrawingPoint drawingPoint in e.OldItems ?? new int )
works just fine.
Why is that?
Why does IList ?? T
work but IList ?? IEnumerable<T>
doesn't?
c# .net collections null-coalescing-operator
2
T
is anIList<T>
, but there is no guarantee that your object that implementsIEnumerable<T>
implementsIList<T>
. You will have to cast yourIList<T>
object toIEnumerable<T>
to use it with?? Enumerable.Empty<T>
.
– Lasse Vågsæther Karlsen
33 mins ago
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
In this question I found the following:
int array = null;
foreach (int i in array ?? Enumerable.Empty<int>())
System.Console.WriteLine(string.Format("0", i));
and
int returnArray = Do.Something() ?? new int ;
and
... ?? new int[0]
In a NotifyCollectionChangedEventHandler
I wanted to apply the Enumerable.Empty
like so:
foreach (DrawingPoint drawingPoint in e.OldItems ?? Enumerable.Empty<DrawingPoint>())
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<WWSmartAufmassWpf.Data.DrawingPoint>
However
foreach (DrawingPoint drawingPoint in e.OldItems ?? new int[0])
and
foreach (DrawingPoint drawingPoint in e.OldItems ?? new int )
works just fine.
Why is that?
Why does IList ?? T
work but IList ?? IEnumerable<T>
doesn't?
c# .net collections null-coalescing-operator
In this question I found the following:
int array = null;
foreach (int i in array ?? Enumerable.Empty<int>())
System.Console.WriteLine(string.Format("0", i));
and
int returnArray = Do.Something() ?? new int ;
and
... ?? new int[0]
In a NotifyCollectionChangedEventHandler
I wanted to apply the Enumerable.Empty
like so:
foreach (DrawingPoint drawingPoint in e.OldItems ?? Enumerable.Empty<DrawingPoint>())
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<WWSmartAufmassWpf.Data.DrawingPoint>
However
foreach (DrawingPoint drawingPoint in e.OldItems ?? new int[0])
and
foreach (DrawingPoint drawingPoint in e.OldItems ?? new int )
works just fine.
Why is that?
Why does IList ?? T
work but IList ?? IEnumerable<T>
doesn't?
c# .net collections null-coalescing-operator
c# .net collections null-coalescing-operator
edited 40 mins ago


Gilad Green
28.7k52953
28.7k52953
asked 41 mins ago
IDarkCoder
1417
1417
2
T
is anIList<T>
, but there is no guarantee that your object that implementsIEnumerable<T>
implementsIList<T>
. You will have to cast yourIList<T>
object toIEnumerable<T>
to use it with?? Enumerable.Empty<T>
.
– Lasse Vågsæther Karlsen
33 mins ago
add a comment |Â
2
T
is anIList<T>
, but there is no guarantee that your object that implementsIEnumerable<T>
implementsIList<T>
. You will have to cast yourIList<T>
object toIEnumerable<T>
to use it with?? Enumerable.Empty<T>
.
– Lasse Vågsæther Karlsen
33 mins ago
2
2
T
is an IList<T>
, but there is no guarantee that your object that implements IEnumerable<T>
implements IList<T>
. You will have to cast your IList<T>
object to IEnumerable<T>
to use it with ?? Enumerable.Empty<T>
.– Lasse Vågsæther Karlsen
33 mins ago
T
is an IList<T>
, but there is no guarantee that your object that implements IEnumerable<T>
implements IList<T>
. You will have to cast your IList<T>
object to IEnumerable<T>
to use it with ?? Enumerable.Empty<T>
.– Lasse Vågsæther Karlsen
33 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
6
down vote
accepted
When using this expression:
a ?? b
Then b
either must be the same type as a
, or it must be implicitly castable to that type, which with references means that it has to implement or inherit from whatever type a
is.
These work:
SomethingThatIsIListOfT ?? new T[0]
SomethingThatIsIListOfT ?? new T
because T
is an IList<T>
, the array type implements that interface.
However, this won't work:
SomethingThatIsIListOfT ?? SomethingThatImplementsIEnumerableOfT
because the type of the expression will be the a
type, and the compiler is obviously unable to guarantee that SomethingThatImplementsIEnumerableOfT
also implements IList<T>
.
You're going to have to cast one of the two sides so that you have compatible types:
(IEnumerable<T>)SomethingThatIsIListOfT ?? SomethingThatImplementsIEnumerableOfT
Now the type of the expression is IEnumerable<T>
and the ??
operator can do its thing.
The "type of the expression will be the type of a
" is a bit simplified, the full text from the specification is as follows:
The type of the expression a ?? b
depends on which implicit conversions are available on the operands. In order of preference, the type of a ?? b
is A0
, A
, or B
, where A
is the type of a (provided that a
has a type), B
is the type of b
(provided that b
has a type), and A0
is the underlying type of A
if A
is a nullable type, or A
otherwise. Specifically, a ?? b
is processed as follows:
- If
A
exists and is not a nullable type or a reference type, a compile-time error occurs. - If
b
is a dynamic expression, the result type is dynamic. At runtime,a
is first evaluated. Ifa
is notnull
,a
is converted to a dynamic type, and this becomes the result. Otherwise,b
is evaluated, and the outcome becomes the result. - Otherwise, if
A
exists and is a nullable type and an implicit conversion exists fromb
toA0
, the result type isA0
. At runtime,a
is first evaluated. Ifa
is notnull
,a
is unwrapped to typeA0
, and it becomes the result. Otherwise,b
is evaluated and converted to typeA0
, and it becomes the result. - Otherwise, if
A
exists and an implicit conversion exists fromb
toA
, the result type isA
. At runtime,a
is first evaluated. Ifa
is not null,a
becomes the result. Otherwise,b
is evaluated and converted to typeA
, and it becomes the result. - Otherwise, if
b
has a typeB
and an implicit conversion exists froma
toB
, the result type isB
. At runtime,a
is first evaluated. Ifa
is notnull
,a
is unwrapped to typeA0
(ifA
exists and is nullable) and converted to typeB
, and it becomes the result. Otherwise,b
is evaluated and becomes the result. - Otherwise,
a
andb
are incompatible, and a compile-time error occurs.
Thank you. In the .NET Documentation on the Array Class you can see that it implementsSystem.Collections.IList
. Is there in equivalent forEnumerable.Empty<T>
forIList
?
– IDarkCoder
26 mins ago
Other thannew T[0]
, I don't know of any, there could be something that I don't know about of course.
– Lasse Vågsæther Karlsen
20 mins ago
add a comment |Â
up vote
1
down vote
I believe that it determines the type of result by the firs member which in your case is IList. The first case works because an array implements IList. With IEnumerable it's not true.
It's just my speculation, as there are no details in the documentation for ?? operator online.
UPD. As it pointed out in accepted question, there are a lot more details on the topic in C# Specification (ECMA or on GitHub)
1
The C# specification has explicit details, I've included it in my own answer.
– Lasse Vågsæther Karlsen
23 mins ago
@LasseVågsætherKarlsen, oh cool, thanks!
– Stas Ivanov
20 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
When using this expression:
a ?? b
Then b
either must be the same type as a
, or it must be implicitly castable to that type, which with references means that it has to implement or inherit from whatever type a
is.
These work:
SomethingThatIsIListOfT ?? new T[0]
SomethingThatIsIListOfT ?? new T
because T
is an IList<T>
, the array type implements that interface.
However, this won't work:
SomethingThatIsIListOfT ?? SomethingThatImplementsIEnumerableOfT
because the type of the expression will be the a
type, and the compiler is obviously unable to guarantee that SomethingThatImplementsIEnumerableOfT
also implements IList<T>
.
You're going to have to cast one of the two sides so that you have compatible types:
(IEnumerable<T>)SomethingThatIsIListOfT ?? SomethingThatImplementsIEnumerableOfT
Now the type of the expression is IEnumerable<T>
and the ??
operator can do its thing.
The "type of the expression will be the type of a
" is a bit simplified, the full text from the specification is as follows:
The type of the expression a ?? b
depends on which implicit conversions are available on the operands. In order of preference, the type of a ?? b
is A0
, A
, or B
, where A
is the type of a (provided that a
has a type), B
is the type of b
(provided that b
has a type), and A0
is the underlying type of A
if A
is a nullable type, or A
otherwise. Specifically, a ?? b
is processed as follows:
- If
A
exists and is not a nullable type or a reference type, a compile-time error occurs. - If
b
is a dynamic expression, the result type is dynamic. At runtime,a
is first evaluated. Ifa
is notnull
,a
is converted to a dynamic type, and this becomes the result. Otherwise,b
is evaluated, and the outcome becomes the result. - Otherwise, if
A
exists and is a nullable type and an implicit conversion exists fromb
toA0
, the result type isA0
. At runtime,a
is first evaluated. Ifa
is notnull
,a
is unwrapped to typeA0
, and it becomes the result. Otherwise,b
is evaluated and converted to typeA0
, and it becomes the result. - Otherwise, if
A
exists and an implicit conversion exists fromb
toA
, the result type isA
. At runtime,a
is first evaluated. Ifa
is not null,a
becomes the result. Otherwise,b
is evaluated and converted to typeA
, and it becomes the result. - Otherwise, if
b
has a typeB
and an implicit conversion exists froma
toB
, the result type isB
. At runtime,a
is first evaluated. Ifa
is notnull
,a
is unwrapped to typeA0
(ifA
exists and is nullable) and converted to typeB
, and it becomes the result. Otherwise,b
is evaluated and becomes the result. - Otherwise,
a
andb
are incompatible, and a compile-time error occurs.
Thank you. In the .NET Documentation on the Array Class you can see that it implementsSystem.Collections.IList
. Is there in equivalent forEnumerable.Empty<T>
forIList
?
– IDarkCoder
26 mins ago
Other thannew T[0]
, I don't know of any, there could be something that I don't know about of course.
– Lasse Vågsæther Karlsen
20 mins ago
add a comment |Â
up vote
6
down vote
accepted
When using this expression:
a ?? b
Then b
either must be the same type as a
, or it must be implicitly castable to that type, which with references means that it has to implement or inherit from whatever type a
is.
These work:
SomethingThatIsIListOfT ?? new T[0]
SomethingThatIsIListOfT ?? new T
because T
is an IList<T>
, the array type implements that interface.
However, this won't work:
SomethingThatIsIListOfT ?? SomethingThatImplementsIEnumerableOfT
because the type of the expression will be the a
type, and the compiler is obviously unable to guarantee that SomethingThatImplementsIEnumerableOfT
also implements IList<T>
.
You're going to have to cast one of the two sides so that you have compatible types:
(IEnumerable<T>)SomethingThatIsIListOfT ?? SomethingThatImplementsIEnumerableOfT
Now the type of the expression is IEnumerable<T>
and the ??
operator can do its thing.
The "type of the expression will be the type of a
" is a bit simplified, the full text from the specification is as follows:
The type of the expression a ?? b
depends on which implicit conversions are available on the operands. In order of preference, the type of a ?? b
is A0
, A
, or B
, where A
is the type of a (provided that a
has a type), B
is the type of b
(provided that b
has a type), and A0
is the underlying type of A
if A
is a nullable type, or A
otherwise. Specifically, a ?? b
is processed as follows:
- If
A
exists and is not a nullable type or a reference type, a compile-time error occurs. - If
b
is a dynamic expression, the result type is dynamic. At runtime,a
is first evaluated. Ifa
is notnull
,a
is converted to a dynamic type, and this becomes the result. Otherwise,b
is evaluated, and the outcome becomes the result. - Otherwise, if
A
exists and is a nullable type and an implicit conversion exists fromb
toA0
, the result type isA0
. At runtime,a
is first evaluated. Ifa
is notnull
,a
is unwrapped to typeA0
, and it becomes the result. Otherwise,b
is evaluated and converted to typeA0
, and it becomes the result. - Otherwise, if
A
exists and an implicit conversion exists fromb
toA
, the result type isA
. At runtime,a
is first evaluated. Ifa
is not null,a
becomes the result. Otherwise,b
is evaluated and converted to typeA
, and it becomes the result. - Otherwise, if
b
has a typeB
and an implicit conversion exists froma
toB
, the result type isB
. At runtime,a
is first evaluated. Ifa
is notnull
,a
is unwrapped to typeA0
(ifA
exists and is nullable) and converted to typeB
, and it becomes the result. Otherwise,b
is evaluated and becomes the result. - Otherwise,
a
andb
are incompatible, and a compile-time error occurs.
Thank you. In the .NET Documentation on the Array Class you can see that it implementsSystem.Collections.IList
. Is there in equivalent forEnumerable.Empty<T>
forIList
?
– IDarkCoder
26 mins ago
Other thannew T[0]
, I don't know of any, there could be something that I don't know about of course.
– Lasse Vågsæther Karlsen
20 mins ago
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
When using this expression:
a ?? b
Then b
either must be the same type as a
, or it must be implicitly castable to that type, which with references means that it has to implement or inherit from whatever type a
is.
These work:
SomethingThatIsIListOfT ?? new T[0]
SomethingThatIsIListOfT ?? new T
because T
is an IList<T>
, the array type implements that interface.
However, this won't work:
SomethingThatIsIListOfT ?? SomethingThatImplementsIEnumerableOfT
because the type of the expression will be the a
type, and the compiler is obviously unable to guarantee that SomethingThatImplementsIEnumerableOfT
also implements IList<T>
.
You're going to have to cast one of the two sides so that you have compatible types:
(IEnumerable<T>)SomethingThatIsIListOfT ?? SomethingThatImplementsIEnumerableOfT
Now the type of the expression is IEnumerable<T>
and the ??
operator can do its thing.
The "type of the expression will be the type of a
" is a bit simplified, the full text from the specification is as follows:
The type of the expression a ?? b
depends on which implicit conversions are available on the operands. In order of preference, the type of a ?? b
is A0
, A
, or B
, where A
is the type of a (provided that a
has a type), B
is the type of b
(provided that b
has a type), and A0
is the underlying type of A
if A
is a nullable type, or A
otherwise. Specifically, a ?? b
is processed as follows:
- If
A
exists and is not a nullable type or a reference type, a compile-time error occurs. - If
b
is a dynamic expression, the result type is dynamic. At runtime,a
is first evaluated. Ifa
is notnull
,a
is converted to a dynamic type, and this becomes the result. Otherwise,b
is evaluated, and the outcome becomes the result. - Otherwise, if
A
exists and is a nullable type and an implicit conversion exists fromb
toA0
, the result type isA0
. At runtime,a
is first evaluated. Ifa
is notnull
,a
is unwrapped to typeA0
, and it becomes the result. Otherwise,b
is evaluated and converted to typeA0
, and it becomes the result. - Otherwise, if
A
exists and an implicit conversion exists fromb
toA
, the result type isA
. At runtime,a
is first evaluated. Ifa
is not null,a
becomes the result. Otherwise,b
is evaluated and converted to typeA
, and it becomes the result. - Otherwise, if
b
has a typeB
and an implicit conversion exists froma
toB
, the result type isB
. At runtime,a
is first evaluated. Ifa
is notnull
,a
is unwrapped to typeA0
(ifA
exists and is nullable) and converted to typeB
, and it becomes the result. Otherwise,b
is evaluated and becomes the result. - Otherwise,
a
andb
are incompatible, and a compile-time error occurs.
When using this expression:
a ?? b
Then b
either must be the same type as a
, or it must be implicitly castable to that type, which with references means that it has to implement or inherit from whatever type a
is.
These work:
SomethingThatIsIListOfT ?? new T[0]
SomethingThatIsIListOfT ?? new T
because T
is an IList<T>
, the array type implements that interface.
However, this won't work:
SomethingThatIsIListOfT ?? SomethingThatImplementsIEnumerableOfT
because the type of the expression will be the a
type, and the compiler is obviously unable to guarantee that SomethingThatImplementsIEnumerableOfT
also implements IList<T>
.
You're going to have to cast one of the two sides so that you have compatible types:
(IEnumerable<T>)SomethingThatIsIListOfT ?? SomethingThatImplementsIEnumerableOfT
Now the type of the expression is IEnumerable<T>
and the ??
operator can do its thing.
The "type of the expression will be the type of a
" is a bit simplified, the full text from the specification is as follows:
The type of the expression a ?? b
depends on which implicit conversions are available on the operands. In order of preference, the type of a ?? b
is A0
, A
, or B
, where A
is the type of a (provided that a
has a type), B
is the type of b
(provided that b
has a type), and A0
is the underlying type of A
if A
is a nullable type, or A
otherwise. Specifically, a ?? b
is processed as follows:
- If
A
exists and is not a nullable type or a reference type, a compile-time error occurs. - If
b
is a dynamic expression, the result type is dynamic. At runtime,a
is first evaluated. Ifa
is notnull
,a
is converted to a dynamic type, and this becomes the result. Otherwise,b
is evaluated, and the outcome becomes the result. - Otherwise, if
A
exists and is a nullable type and an implicit conversion exists fromb
toA0
, the result type isA0
. At runtime,a
is first evaluated. Ifa
is notnull
,a
is unwrapped to typeA0
, and it becomes the result. Otherwise,b
is evaluated and converted to typeA0
, and it becomes the result. - Otherwise, if
A
exists and an implicit conversion exists fromb
toA
, the result type isA
. At runtime,a
is first evaluated. Ifa
is not null,a
becomes the result. Otherwise,b
is evaluated and converted to typeA
, and it becomes the result. - Otherwise, if
b
has a typeB
and an implicit conversion exists froma
toB
, the result type isB
. At runtime,a
is first evaluated. Ifa
is notnull
,a
is unwrapped to typeA0
(ifA
exists and is nullable) and converted to typeB
, and it becomes the result. Otherwise,b
is evaluated and becomes the result. - Otherwise,
a
andb
are incompatible, and a compile-time error occurs.
edited 16 mins ago
answered 30 mins ago
Lasse Vågsæther Karlsen
279k80509707
279k80509707
Thank you. In the .NET Documentation on the Array Class you can see that it implementsSystem.Collections.IList
. Is there in equivalent forEnumerable.Empty<T>
forIList
?
– IDarkCoder
26 mins ago
Other thannew T[0]
, I don't know of any, there could be something that I don't know about of course.
– Lasse Vågsæther Karlsen
20 mins ago
add a comment |Â
Thank you. In the .NET Documentation on the Array Class you can see that it implementsSystem.Collections.IList
. Is there in equivalent forEnumerable.Empty<T>
forIList
?
– IDarkCoder
26 mins ago
Other thannew T[0]
, I don't know of any, there could be something that I don't know about of course.
– Lasse Vågsæther Karlsen
20 mins ago
Thank you. In the .NET Documentation on the Array Class you can see that it implements
System.Collections.IList
. Is there in equivalent for Enumerable.Empty<T>
for IList
?– IDarkCoder
26 mins ago
Thank you. In the .NET Documentation on the Array Class you can see that it implements
System.Collections.IList
. Is there in equivalent for Enumerable.Empty<T>
for IList
?– IDarkCoder
26 mins ago
Other than
new T[0]
, I don't know of any, there could be something that I don't know about of course.– Lasse Vågsæther Karlsen
20 mins ago
Other than
new T[0]
, I don't know of any, there could be something that I don't know about of course.– Lasse Vågsæther Karlsen
20 mins ago
add a comment |Â
up vote
1
down vote
I believe that it determines the type of result by the firs member which in your case is IList. The first case works because an array implements IList. With IEnumerable it's not true.
It's just my speculation, as there are no details in the documentation for ?? operator online.
UPD. As it pointed out in accepted question, there are a lot more details on the topic in C# Specification (ECMA or on GitHub)
1
The C# specification has explicit details, I've included it in my own answer.
– Lasse Vågsæther Karlsen
23 mins ago
@LasseVågsætherKarlsen, oh cool, thanks!
– Stas Ivanov
20 mins ago
add a comment |Â
up vote
1
down vote
I believe that it determines the type of result by the firs member which in your case is IList. The first case works because an array implements IList. With IEnumerable it's not true.
It's just my speculation, as there are no details in the documentation for ?? operator online.
UPD. As it pointed out in accepted question, there are a lot more details on the topic in C# Specification (ECMA or on GitHub)
1
The C# specification has explicit details, I've included it in my own answer.
– Lasse Vågsæther Karlsen
23 mins ago
@LasseVågsætherKarlsen, oh cool, thanks!
– Stas Ivanov
20 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
I believe that it determines the type of result by the firs member which in your case is IList. The first case works because an array implements IList. With IEnumerable it's not true.
It's just my speculation, as there are no details in the documentation for ?? operator online.
UPD. As it pointed out in accepted question, there are a lot more details on the topic in C# Specification (ECMA or on GitHub)
I believe that it determines the type of result by the firs member which in your case is IList. The first case works because an array implements IList. With IEnumerable it's not true.
It's just my speculation, as there are no details in the documentation for ?? operator online.
UPD. As it pointed out in accepted question, there are a lot more details on the topic in C# Specification (ECMA or on GitHub)
edited 14 mins ago
answered 31 mins ago


Stas Ivanov
195211
195211
1
The C# specification has explicit details, I've included it in my own answer.
– Lasse Vågsæther Karlsen
23 mins ago
@LasseVågsætherKarlsen, oh cool, thanks!
– Stas Ivanov
20 mins ago
add a comment |Â
1
The C# specification has explicit details, I've included it in my own answer.
– Lasse Vågsæther Karlsen
23 mins ago
@LasseVågsætherKarlsen, oh cool, thanks!
– Stas Ivanov
20 mins ago
1
1
The C# specification has explicit details, I've included it in my own answer.
– Lasse Vågsæther Karlsen
23 mins ago
The C# specification has explicit details, I've included it in my own answer.
– Lasse Vågsæther Karlsen
23 mins ago
@LasseVågsætherKarlsen, oh cool, thanks!
– Stas Ivanov
20 mins ago
@LasseVågsætherKarlsen, oh cool, thanks!
– Stas Ivanov
20 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52380876%2fnull-coalescing-operator-ilist-array-enumerable-empty-in-foreach%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
T
is anIList<T>
, but there is no guarantee that your object that implementsIEnumerable<T>
implementsIList<T>
. You will have to cast yourIList<T>
object toIEnumerable<T>
to use it with?? Enumerable.Empty<T>
.– Lasse Vågsæther Karlsen
33 mins ago