“EnumerableToArray” (Problem)
What will the following code display?
1
public static string GetString(string s)
2
{
3
Console.WriteLine("GetString: " + s);
4
return s;
5
}
6
public static IEnumerable<string> GetStringEnumerable()
7
{
8
yield return GetString("Foo");
9
yield return GetString("Bar");
10
}
11
public static string[] EnumerableToArray()
12
{
13
var strings = GetStringEnumerable();
14
foreach (var s in strings)
15
Console.WriteLine("EnumerableToArray: " + s);
16
return strings.ToArray();
17
}
18
void Main()
19
{
20
EnumerableToArray();
21
}
Copied!
Solution
Copy link