logo logo
Home arrow Forums...
Monday, 06 October 2008
 
 
English English  Español Español  
Tag Cloud
Architectures Artificial Associations Books Brain Conscious Consciousness Forums Howto Machine Machine Consciousness Machines Microsoft Neuroscience Projects Publications Research Researchers Reviews Robot Robotics Robots Services Studio
Conscious-Robots.com Forum  


Raúl
Moderator

Moderator
Posts: 388
graph
Karma: 6  
What is that yield return, yield break thing? - 2007/12/22 19:55 If you are new to C# 2.0 and you've been having a look to Microsoft Robotics Studio sample code, you've probably wondered what is that yield return and yield break statements... All is about iterators.

Have a look to this article:

http://www.conscious-robots.com/en/robotics-studio/robotics-studio-howto/how-to-use-the-new- features-of-2.html

Post edited by: Raúl, at: 2007/12/22 19:58
Raúl Arrabales Moreno. conscious-robots.com/raul
  The administrator has disabled public write access. Please, register to participate in the forum.
Raúl
Moderator

Moderator
Posts: 388
graph
Karma: 6  
Re:What is that yield return, yield break thing? - 2007/12/22 19:58 When you look for the first time to the C# sample code provided with Robotics Studio you will notice that some new features of this language are extensively used. Statements like yield return, yield break, and IEnumerator<ITask> might call your attention.

Basically, all of this is about Iterators. If you are new to C# 2.0 and want to program robotics applications using Robotics Studio you should clearly understand how Iterators are used.

Iterators can be methods, get accessors or operators that support foreach interation in a class. Usually, if you want to use the foreach statement with a given class you need to implement the IEnumerable interface. However, using Iterators allows you to support foreach iteration in a class without having to implement the entire IEnumerable interface. You just need to write an iterator able to sequentially access the data structures contained in your class. The Visual Studio compiler detects iterators and automatically generates the IEnumerable methods Current, MoveNext and Dispose.

When writting iterators code, the statement yield return is used to return each element in turn, while yield break ends the iteration. The elements returned by yield return <expression> have to be of type IEnumerable or IEnumerator. In the case of Robotics Studio, when we are using the CCR, we usually return a IEnumerator<ITask> (as the generics IEnumerable<T> and IEnumerator<T> can also be used with iterators). Basically, what we are doing is dispatching a collection of tasks.

Have a look to the following links for a detailed explanation and sample code:


C# Programming Guide: Iterators: http://msdn2.microsoft.com/en-us/library/dscyy5s0(VS.80).aspx
yield statement (C# Reference): http://msdn2.microsoft.com/en-us/library/9k7k7cf0(VS.80).aspx
foreach statement (C# reference): http://msdn2.microsoft.com/en-us/library/ttw7t8t6(VS.80).aspx
Using Iterators (C# Programming Guide): http://msdn2.microsoft.com/en-us/library/65zzykke(VS.80).aspx
Raúl Arrabales Moreno. conscious-robots.com/raul
  The administrator has disabled public write access. Please, register to participate in the forum.





Lost Password?
No account yet? Register
Last Posts in Forum
Last comments
My review of Conscious Machines
Review of the book ‘The Co...
23/09/08 12:32 More...
By Raúl

Re: How do i use this in a simulated rob
Hi, let me answer...
12/08/08 14:46 More...
By Raúl

How do i use this in a simulated robot?
I\'m entirely new ...
10/08/08 16:30 More...
By carlcs

How do i use this in a simulated robot?
I\'m entirely new ...
10/08/08 16:29 More...
By carlcs

Foro de Robotics Studio en Español
Hola sutaro, he copiado...
17/07/08 14:32 More...
By Raúl

fallo de ejecución:Unhandled within caus
Hola a todos, es ...
17/07/08 13:03 More...
By sutaro

Amazed Challenge 2
Good news for those of you who missed t...
03/07/08 11:21 More...
By Raúl

Poster Session Pictures
Some pictures of the poster sessio...
08/04/08 13:17 More...
By Raúl

Final Announcement and Conference Overvi
Final Announcemen...
07/02/08 12:45 More...
By Raúl

Discussion about test for consciousness
More information a...
29/01/08 15:01 More...
By Raúl

 
Top! Top!