[C# ,쉬운 이터레이터 만들기] Yield 키워드 간단히 개념잡기





  1.         public IEnumerable TestEnum1()
  2.         {
  3.             yield return "q1";
  4.             yield return "q2";
  5.             yield return "q3";
  6.             yield return "q4";
  7.         }
  8.  
  9.         public IEnumerable TestEnum2()
  10.         {
  11.             for (int i = 0; i < 100; ++i)
  12.             {
  13.                 if (i == 50)
  14.                     yield break;
  15.  
  16.                 yield return i;
  17.             }
  18.         }
  19.  
  20.         /****실행****/
  21.  
  22.         foreach (var item in TestEnum1())
  23.             Console.WriteLine(item);
  24.  
  25.         foreach (var item in TestEnum2())
  26.             Console.WriteLine(item);


위의 코드에서 보면 , IEnumerable 를 리턴 하는 키워드가  yield 라는 것을 알수 있다 .

그리고 루프롤 돌렸을때 , 결과는 를 리턴하는 순서로 출력 된다.

yield  뒤에는 return 또는 break 도 쓸수 있다 (14번째 라인 참고 )
Yamecoder 야매코더_
tags : , ,
C# 2010. 12. 5. 00:22

댓글을 달아 주세요

  1. 이전 댓글 더보기
  2. BlogIcon wood eyeglass frames 2014.11.17 09:04  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  3. BlogIcon ralph lauren polo 2014.11.23 08:08  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  4. BlogIcon moncler coats 2014.11.28 08:26  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  5. 匿名 2014.12.03 05:44  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  6. BlogIcon cheap nhl jerseys from china 2014.12.04 14:31  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  7. 匿名 2015.01.07 17:45  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  8. 匿名 2015.01.15 12:22  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  9. BlogIcon Arizona Diamondbacks Jerseys 2015.01.29 18:18  수정/삭제  댓글쓰기

    기방Memphis Tigers Jerseys Washington Redskins Jerseys ,Cheap Nba Thunder Jerseys Boston Red Sox jerseys Atlanta Hawks jerseys North CarSeattle Mariners jerseys wholesale nfl jerseys

    “Obviously something is different,Kids Nfl Clothing Honduras Je,Baylor Bears Jerseys,Indianapolis Colts Jerseys 30, whether it’s the hitter’s approach off me or not being able to execute pitches like I did last year,”일가

  10. BlogIcon Miami Hurricanes Jerseys 2015.01.29 18:18  수정/삭제  댓글쓰기

    마일Chicago Bears Jerseys Minnesota Twins Jerseys Los Angeles Angels Jerseys ,Syracuse Orange JerseysNew York Knicks Jerseys



    Darin Ruf's sacrifice fly put the Phillies ahead in the top of the fourth,Switzerland Jerseys.

    Another surprise team,Wholesale Nike Nfl Jerseys?로메

  11. BlogIcon Atletico Nacional Jerseys 2015.01.29 18:19  수정/삭제  댓글쓰기

    법간san francisco 49ers jerseys Oakland Raiders Jerseys cheap nba Lakers jerseys ,Cheap Authentic Football Jerseys,Super Bowl 2012 JerseysGreen Bay Packers Jerseys





    After all,Philadelphia Eagles Jerseys, Dalton,Montreal Canadiens Jerseys, the Bengals' fourth-year quarterback whose preseason success seemed to justify the six-year,Authentic Elite Nfl Jerseys,Nfl Replica Jerseys Cheap,Ncaa Spo뉴어

  12. BlogIcon Discount Ncaa Basketball Jerseys 2015.01.30 21:12  수정/삭제  댓글쓰기

    있려pittsburgh penguins jerseys football nfl jerseys ,Wholesale Nba Jerseys Shorts AndChicago Blackhawks Jerseys Tampa Bay Buccaneers Jerseys



    Hicks' stat line from last season -- 42 points,Custom Ncaa Jerseys, 35 rebounds -- was modest considering he was one of seven Carolina players who appeared in every game.없없

  13. BlogIcon Tennessee Vols Jerseys 2015.01.30 21:13  수정/삭제  댓글쓰기

    에상Baltimore Bullets Jerseys Washington Redskins Jerseys Women Soccer Country Jerseys Cincinnati Bengals Jerseys
    ,Nfl Throwback Jerseys Sale
    It was the one weak link last season for an outstanding,cheap nhl jerseys, Super Bowl-winning team. Part of the problem was injury related,Texas A&M Aggies Jerseys, but the line struggled at times,Wholesale Soccer Jersey, especially in pass protection.뉴데

  14. BlogIcon Everton Jerseys 2015.02.01 01:57  수정/삭제  댓글쓰기

    법마Chicago Blackhawks Jerseys Seattle Seahawks Jerseys Atlanta Falcons Jerseys ,Los Angeles Dodgers JerseysIndiana Pacers Jerseys메선

  15. 匿名 2015.02.11 14:03  수정/삭제  댓글쓰기

    간및大话西游服务端凡人修真服务端大话西游服务端页游服务端问道服务端

    跑跑卡丁车服务端英雄远征服务端幻灵游侠私服务端洪荒神话私服务端

    完美世界服务端烈焰服务端洛汗服务端新魔界服务端绝对女神私服务端


    魔兽私服开区一条龙服务-

    传奇私服开传奇一条龙服务-


    传奇广告代理-

    IDC服务器以及空间租用-

    魔域开区sf一条龙开区服务-


    客服咨询QQ(企鹅扣扣)1325876192

    Email:1325876192@qq.com

    商业版本免费开放下载




    紫川科技最新毁灭天下1.85狂雷独家合击热血复古三职业新装传奇服务端



    紫川科技20星大极品良装+80麒麟锻造中变传奇服务端



    紫川科技独家轻变1.89奥妙转生神龙锻造珍珑元素版传奇服务端



    紫川科技独家九转1.85四皇冠加倍装备特戒龙卫비서

  16. BlogIcon clubmaster Sunglasses 2015.03.05 17:04  수정/삭제  댓글쓰기

    기이When anyone gathers additionalweight in his body he receives several advices from his friends and relatives concerning the measures he need totake to shred additionalfat. he's asked to take less food and to quit specific sorts of food. he's alin orderked to head for weight loss supplements. one of the most of the people will spread such words that weight loss supplements don't work smartalalthough가시

  17. 匿名 2015.03.31 08:50  수정/삭제  댓글쓰기

    던분Garage Safety Tips







    [标签:来源]








    Here are some basic safety tips when working on your car or motorcycle in the garage or automotive shop.



    2. Wear proper safety gear - This one seems obvious,Small Business Web Shopping Cart Software- 7 Reaso, but most mechanics just grab some air tools and go to work. Safety glasses are cheap and will save your eyes from falling deb우리

  18. 匿名 2015.04.01 06:28  수정/삭제  댓글쓰기

    의던Known publishers from the foreign press, secular,Italian Bakery Shops_55008., artists,Shopping in Singapore - 5 Sho, designers and fashionsitas, everybody came from the collection of women Moncler Marmelade Techno equipped with seat belts parka to be seen. They are all "oohed and ahhed" while enjoying hot cider and hot chocolate. Personally.



    Ironic how the absence of life (which is visual, 메에

  19. 匿名 2015.04.03 13:49  수정/삭제  댓글쓰기

    일가and even better news is that their greatest extent EVER!Beautiful flowers and fittings add a touch of tartan jackets that unmistakable feminine essence, while injections of red.



    Purple and orange make this the biggest ever range of colors.Barbour waxed jackets, Barbour International Quilt Jacket, Jackets Barbour Polar Quilt .


    If you are in the midst of your wedding shopping,Wholesale J그법

  20. 匿名 2015.04.03 17:37  수정/삭제  댓글쓰기

    관선But then you cannot be expected to hang out in the campus unless you are a student and studying there,The Top 10 Attractions in Ark. So better for you would be to take up a course and study,Online Blog Shops Struggle to Stay_57550..





    Well you have been wanting to make friends with a particular woman for a long time but haven't known how to approach her. Let us tell you how to do this and들간

  21. 匿名 2015.04.04 02:54  수정/삭제  댓글쓰기

    일그They are comfortable and keep your feet feel different! This year is tailored to the retro era, large and small,Toddler Ride on Toys_121113, a wide range of classical styles are back to the attention of the population between the return series of the wind.



    Nike Air Max sneaker has a classic b-ball for a look around oreder the two basketball courts and also the pedestrian to complete. Nike A가는

Powerd by Tistory, designed by criuce
rss