Advertisement
DefconDotNet

weird yield stuff

Mar 14th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ConsoleApplication1
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             try {
  11.                 var upperFoo = MakeUppercase(null);
  12.  
  13.                 Console.Write("Uppercased!");
  14.             }
  15.             catch (ArgumentNullException)
  16.             {
  17.                 Console.Write("Exeption");
  18.             }
  19.         }
  20.  
  21.         public static IEnumerable<char> MakeUppercase(string foo)
  22.         {
  23.             if (foo == null)
  24.                 throw new ArgumentNullException("foo");
  25.  
  26.             foreach (var chr in foo)
  27.                 yield return Char.ToUpperInvariant(chr);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement