.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

What is the use of "Yield" key word in C# 2.0?

Posted By: Sajid P K     Posted Date: October 11, 2010    Points:2   Category :C#
Hi All,

What is the use of "Yield" key word in C# 2.0?

Sajid P K

Author: Syed Shakeer Hussain             
Posted Date: October 11, 2010     Points: 5   


The yield keyword is used in an iterator block to provide a value to the enumerator object or to signal the end of the iteration. When used the expression is evaluated and returned as a value to the enumerator object. Note the expression has to be implicitebly convertible to yield type of the iterator. Here is an example

public static IEnumerable<int> GetIntCollectionFromString(string SomeString)


string[] val = SomeString.Split(' ');

int intVal;

foreach (string token in val)


if (int.TryParse(token, out intVal))


yield return intVal;




yield break;




For more information check the below links



Author: Sajid P K             
Posted Date: October 11, 2010     Points: 5   

Thanks Lot..

Sajid P K

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend