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


Top 5 Contributors of the Month
david stephan

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?

Thanks
Sajid P K



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

Hi,




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;

}

else

{

yield break;

}

}

}




For more information check the below links





1)http://www.c-sharpcorner.com/UploadFile/rmcochran/yieldreturn04022006113850AM/yieldreturn.aspx

2)http://dotnetperls.com/yield





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

Thanks Lot..

Regards,
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
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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