yield让代码更加简洁

不能传入out或ref   
public IEnumerable<Shop> GetShop() { for (int i = 1; i < 11; i++) { yield return new Shop { ID = i, Name = "Shop-" + i }; } }

 

你可能感兴趣的:(yield)