Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using static System.Console;
- namespace DelegateVsFunc
- {
- public delegate void StringCharCallback(char c);
- public static class Extensions
- {
- public static void ForEach(this string str, StringCharCallback callback)
- {
- foreach (var c in str)
- {
- callback(c);
- }
- }
- public static void ForEach(this string str, Action<char> callback)
- {
- str.ForEach(callback);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- string str = "abcdefg";
- //Miksi pitää castata?
- str.ForEach((StringCharCallback)((c) => WriteLine(c)));
- ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement