From 8ce6c223d11f5b7cadab0dc1aef3c47486f09abb Mon Sep 17 00:00:00 2001 From: syneffort Date: Fri, 28 Apr 2023 13:50:59 +0900 Subject: [PATCH] delegate (predicate) --- DevTips/DevTips/Program.cs | 5 ++++- DevTips/DevTips/Tips/DelegateClient.cs | 28 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 DevTips/DevTips/Tips/DelegateClient.cs diff --git a/DevTips/DevTips/Program.cs b/DevTips/DevTips/Program.cs index b335e67..18c90cb 100644 --- a/DevTips/DevTips/Program.cs +++ b/DevTips/DevTips/Program.cs @@ -20,6 +20,9 @@ class Program // FuncClient.Client(); // Predicate - PreicateClient.Client(); + // PreicateClient.Client(); + + // Delegate + DelegateClient.Client(); } } diff --git a/DevTips/DevTips/Tips/DelegateClient.cs b/DevTips/DevTips/Tips/DelegateClient.cs new file mode 100644 index 0000000..93136d6 --- /dev/null +++ b/DevTips/DevTips/Tips/DelegateClient.cs @@ -0,0 +1,28 @@ +using System; +using System.Linq; + +namespace DevTips.Tips; + +class DelegateClient +{ + public static void Client() + { + int[] arr = { -10, 20, -30, 4, -5 }; + + System.Console.WriteLine("Find"); + int pos = Array.Find(arr, IsPositive); + System.Console.WriteLine(pos); + + System.Console.WriteLine("n >= 0"); + var v = arr.Where(n => n >= 0); + foreach (var elem in v) + { + System.Console.WriteLine(elem); + } + } + + private static bool IsPositive(int i) + { + return i >= 0; + } +} \ No newline at end of file