Advertisement
elena1234

CustomMinFunction- how to use Func< >

Jan 25th, 2021 (edited)
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace CustomMinFunction
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11.             Func<int[], int> funcMinNumber = nums =>
  12.              {
  13.                  int minValue = int.MaxValue;
  14.                  foreach (var num in numbers)
  15.                  {
  16.                      if (num < minValue)
  17.                      {
  18.                          minValue = num;
  19.                      }
  20.                  }
  21.  
  22.                  return minValue;
  23.              };
  24.  
  25.             Console.WriteLine(funcMinNumber(numbers));
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement