yield-keyword

Why can't yield return appear inside a try block with a catch?

The following is okay: try { Console.WriteLine("Before"); yield return 1; Console.WriteLine("After"); } finally { Console.WriteLine("Done"); } The finally block runs when the whole thing has finished executing (IEnumerator<T> supports IDisposable to provide a way to ensure this even when the enumeration is abandoned ...

how can a compiler that recognizes the iterators be implemented?

I have been using iterators for a while and I love them. But although I have thought hard about it, I could not figure out "how a compiler that recognizes the iterators" be implemented. I have also researched about it, but could not find any resource explaining the situation in the compiler-design context. To elaborate, most of the art...

scala for yield setting a value

Hi, I want to create a list of GridBagPanel.Constraints. I read it in the scala programming book, that there is a cool for-yield construction, but I probably haven't understood the way it works correctly, because my code doesn't compile. Here it is: val d = for { i <- 0 until 4 j <- 0 until 4 } yi...

Is using YIELD a read-only way to return a collection?

I'm writing an interface which has a collection property which I want to be read only. I don't want users of the interface to be able to modify the collection. The typical suggestion I've found for creating a read only collection property is to set the type of the property to IEnumerable like this: private List<string> _mylist; public I...