yield
only works with IEnumerable<T>
, IEnumerable
, IEnumerator<T>
and IEnumerator
as return type.
In your case, you need to use a normal method instead:
public IList<string> method()
{
var result = new List<string>();
for (int i = 0; i < 1000; i++)
{
result.Add(i.ToString());
}
return result;
}
Think about it. Your code would allow you to write the following code:
method().Add("foo");
That doesn't make too much sense, does it?