Created
July 8, 2018 17:51
-
-
Save tylerlrhodes/921f6bf07919f555b0e158d5912f281d to your computer and use it in GitHub Desktop.
Demo of higher order function in c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace HigherOrderProceduresDemo | |
{ | |
class Program | |
{ | |
static void Map(IEnumerable<int> list, Action<int> fn) | |
{ | |
foreach (var item in list) | |
fn(item); | |
} | |
static void Main(string[] args) | |
{ | |
void PrintTimes2(int a) => Console.WriteLine((a * 2).ToString()); | |
var list = new List<int>() | |
{ | |
1, | |
2, | |
3, | |
4, | |
5 | |
}; | |
Map(list, PrintTimes2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment