Here is a example of using yield:

public static IEnumerable<int> Unique(IEnumerable<int> nums)
{
Dictionary<int, int> uniqueVals = new
Dictionary<int, int>();
foreach (int num in nums)
{
if (!uniqueVals.ContainsKey(num))
{
uniqueVals.Add(num, num);
yield return num;
}
}
}


Dompare the typical way and the "yield" to get IEnumerable

# IList<string> FindBobs(IEnumerable<string> names)  
# {
# var bobs = new List<string>();
#
# foreach(var currName in names)
# {
# if(currName == "Bob")
# bobs.Add(currName);
# }
#
# return bobs;
# }
# IEnumerable<string> FindBobs(IEnumerable<string> names)  
# {
# foreach(var currName in names)
# {
# if(currName == "Bob")
# yield return currName;
# }
# }



 
Friday, 19 August 2011 02:59:12 (Eastern Daylight Time, UTC-04:00)
watches for sale replica cartier watches replica cartier fake omega watches replica omega watches for sale swiss watch fake rolex watches watches rolex swiss watches asking tag heuer replica tag heuer replica wrist watches replica watch royal oak watches miglia fake breitling watches watches breitling.
Friday, 19 August 2011 03:30:18 (Eastern Daylight Time, UTC-04:00)
tsubmersible watches replica watch breitling superocean heritage bowed replica breitling replica breitling watches for sale replica cartier watches replica cartier fake iwc watches caise omega replica replica omega rolex replica fake rolex watches Duty aquanaut watches replica tag heuer watches for sale replica tag heuer.
Tuesday, 27 September 2011 04:16:14 (Eastern Daylight Time, UTC-04:00)
chronomat evolution watches cartier cartier replica fake omega watches fake omega watches u boat watches replica rolex watches for sale fake rolex watches for sale superocean watches blind watches tag heuer replica tag heuer replica tissot watches watches replica oris watches olympic fake breitling watches fake breitling watches.
Sunday, 19 February 2012 20:19:55 (Eastern Standard Time, UTC-05:00)
best watches replica jaeger lecoultre bulova watch replica iwc swiss watches replica chopard mens watch brands.
Sunday, 19 February 2012 21:05:39 (Eastern Standard Time, UTC-05:00)
Wholesale clothing BCBG Pullovers Long black dress Karen Millen Short Sleeved Dresses Cocktail dresses cocktail dresses Christian Audigier Vests Clothing and fashion Christian Audigier Leather and Suede Vintage sunglasses BCBG Wear to Work Vintage baby.
Monday, 20 February 2012 23:57:13 (Eastern Standard Time, UTC-05:00)
discount designer watches replica watches for sale breitling watch fake breitling discount designer watches.
Tuesday, 21 February 2012 21:17:09 (Eastern Standard Time, UTC-05:00)
Vintage pictures Gucci Prom Dresses Formal gowns BCBG Jackets Overstitching Casual Dresses Blazers online Wedding Dresses Dresses party Christian Audigier Suits Clothes fashion.
Comments are closed.