This is valid code:
void func(IEnumerable<string> strings){
foreach(string s in strings){
Console.WriteLine(s);
}
}
string[] ss = new string[]{"asdf", "fdsa"};
func(ss);
What I want to know is, how does the implicit conversion string[] -> IEnumerable<string>
work?
from: msdn Array Class
In the .NET Framework version 2.0, the Array class implements the
IList<T>
,ICollection<T>
, andIEnumerable<T>
generic interfaces. The implementations are provided to arrays at run time, and therefore are not visible to the documentation build tools. As a result, the generic interfaces do not appear in the declaration syntax for the Array class, and there are no reference topics for interface members that are accessible only by casting an array to the generic interface type (explicit interface implementations). The key thing to be aware of when you cast an array to one of these interfaces is that members which add, insert, or remove elements throw
NotSupportedException
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With