Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- начин 1:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _3._Custom_Min_Function
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
- //приема списък -> връща най-малкото число в списъка
- Func<List<int>, int> getMinElement = list => list.Min();
- Console.WriteLine(getMinElement(numbers));
- }
- }
- }
- начин 2:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _3._Custom_Min_Function
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
- //приема списък -> печатаме най-малкото число в списъка
- Func<List<int>, int> getMinElement = list =>
- {
- int min = int.MaxValue;
- foreach(int number in list)
- {
- if (number < min)
- {
- min = number;
- }
- }
- return min;
- };
- Console.WriteLine(getMinElement(numbers));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement