Advertisement
Janne252

Untitled

Oct 2nd, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using static System.Console;
  3.  
  4. namespace DelegateVsFunc
  5. {
  6.     public delegate void StringCharCallback(char c);
  7.  
  8.     public static class Extensions
  9.     {
  10.         public static void ForEach(this string str, StringCharCallback callback)
  11.         {
  12.             foreach (var c in str)
  13.             {
  14.                 callback(c);
  15.             }
  16.         }
  17.  
  18.         public static void ForEach(this string str, Action<char> callback)
  19.         {
  20.             str.ForEach(callback);
  21.         }
  22.     }
  23.  
  24.     class Program
  25.     {    
  26.         static void Main(string[] args)
  27.         {
  28.             string str = "abcdefg";
  29.  
  30.             //Miksi pitää castata?
  31.             str.ForEach((StringCharCallback)((c) => WriteLine(c)));
  32.            
  33.             ReadLine();
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement