본문 바로가기


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

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

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

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

yield  뒤에는 return 또는 break 도 쓸수 있다 (14번째 라인 참고 )


  • 이전 댓글 더보기
  • BlogIcon wood eyeglass frames 2014.11.17 09:04

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

  • BlogIcon ralph lauren polo 2014.11.23 08:08

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

  • BlogIcon moncler coats 2014.11.28 08:26

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

  • 匿名 2014.12.03 05:44

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

  • BlogIcon cheap nhl jerseys from china 2014.12.04 14:31

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

  • 匿名 2015.01.07 17:45

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

  • 匿名 2015.01.15 12:22

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

  • 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,”일가

  • 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?로메

  • 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뉴어

  • 있려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.없없

  • 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.뉴데

  • BlogIcon Everton Jerseys 2015.02.01 01:57

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

  • 匿名 2015.02.11 14:03
















  • 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가시

  • 匿名 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우리

  • 匿名 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, 메에

  • 匿名 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그법

  • 匿名 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들간

  • 匿名 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가는