yield-return

IEnumerable yield return combined with .AsParallel()

I've written some code to try and describe my concern: static void Main(string[] args) { IEnumerable<decimal> marks = GetClassMarks(); IEnumerable<Person> students = GetStudents(); students.AsParallel().ForAll(p => GenerateClassReport(p, marks)); Console.ReadKey(); } GetClassMarks uses yield return in it from my weir...

Scala implementation of C#-like yield with "for"

I'm trying to use various scala implementations of C#-like yield return (i.e. link text) with "for" -constructions such as: private def permutations[T](s: Vector[T]) = { def swap(i: Int, j: Int) { val tmp = s(i) s.set(i, s.get(j)) s.set(j, tmp) } iterator[Vector[T]] { def generate(left: Int, right: Int): Unit @cps...

C# - Serialization and the Yield statement

Is it possible to serialize a method containing yield statements (or a class that contains such a method) such that when you rehydrate the class, the internal state of the generated iterator is retained? ...

If yield return never occurs, is null returned?

The method returns IEnumerable via a yield return statement. If the yield statement never occurs (it's inside conditional logic), will the method return null, or will it return an Enumerable with a count of 0? ...

How does this function work in detail?

I got this method (inside a Unity C# Script), but I do not understand how the "yield" part actually works. I know from the MSDN that the function will return an IEnumerator which I could iterate throught, but this code waits 1,5 seconds and does not get iterated because this would mean, the objects created inside were created multiple t...

What concrete type does 'yield return' return?

What is the concrete type for this IEnumerable<string>? private IEnumerable<string> GetIEnumerable() { yield return "a"; yield return "a"; yield return "a"; } ...

Objective-C Yield/Wait for function to return?

Hello! In objective c how would you get a function to pause until another one returns? Thanks! Christian Stewart ...

iterator block to LINQ

I'm having a hard time finding the right LINQ syntax to use for the following iterator block: class Program { class Operation { public IEnumerable<Operation> NextOperations { get; private set; } } class Item { } static Item GetItem(Operation operation) { return new Item(); } static IEnum...

Is there ever a reason to not use 'yield return' when returning an IEnumerable?

Simple example - you have a method or a property that returns an IEnumerable and the caller is iterating over that in a foreach() loop. Should you always be using 'yield return' in your IEnumerable method? Is there ever a reason not to? While I understand that it may not always be necessary to, or even "better" (maybe it's a very smal...

When NOT to use yield (return)

Possible Duplicate: Is there ever a reason to not use 'yield return' when returning an IEnumerable? There are several useful questions here on SO about the benefits of yield return. For example, Can someone demystify the yield keyword Interesting use of the c# yield keyword What is the yield keyword There is also a ques...

.NET iterator to wrap throwing API

Hi. I have a class with an API that allows me to ask for objects until it throws an IndexOutOfBoundsException. I want to wrap it into an iterator, to be able to write cleaner code. However, I need to catch the exception to stop iterating: static IEnumerable<object> Iterator( ExAPI api ) { try { for( int i = 0; true; ++i ) ...