Advertisement
desislava_topuzakova

03. Custom Min Function

Jun 3rd, 2022
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. начин 1:
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace _3._Custom_Min_Function
  7. {
  8. internal class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  13.  
  14. //приема списък -> връща най-малкото число в списъка
  15. Func<List<int>, int> getMinElement = list => list.Min();
  16.  
  17. Console.WriteLine(getMinElement(numbers));
  18.  
  19. }
  20. }
  21. }
  22.  
  23. начин 2:
  24. using System;
  25. using System.Collections.Generic;
  26. using System.Linq;
  27.  
  28. namespace _3._Custom_Min_Function
  29. {
  30. internal class Program
  31. {
  32. static void Main(string[] args)
  33. {
  34. List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  35.  
  36. //приема списък -> печатаме най-малкото число в списъка
  37. Func<List<int>, int> getMinElement = list =>
  38. {
  39. int min = int.MaxValue;
  40. foreach(int number in list)
  41. {
  42. if (number < min)
  43. {
  44. min = number;
  45. }
  46. }
  47.  
  48. return min;
  49. };
  50.  
  51. Console.WriteLine(getMinElement(numbers));
  52.  
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement