Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace GenericCountMethodDouble
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class GenericCountMethodDouble
- {
- public static void Main()
- {
- List<Box<double>> boxes = new List<Box<double>>();
- int boxCount = Int32.Parse(Console.ReadLine());
- for (int i = 0; i < boxCount; i++)
- {
- boxes.Add(new Box<double>(double.Parse(Console.ReadLine())));
- }
- Box<double> comparableBox = new Box<double>(double.Parse(Console.ReadLine()));
- int countOfGreaterelements = CompareElements(boxes, comparableBox);
- Console.WriteLine(countOfGreaterelements);
- }
- static int CompareElements<T>(List<Box<T>> boxes, Box<T> comparableBox)
- where T : IComparable<T>
- {
- int count = boxes.Count(b => b.Value.CompareTo(comparableBox.Value) > 0);
- return count;
- }
- }
- public class Box<T> where T : IComparable<T>
- {
- private T value;
- public Box()
- : this(default(T))
- {
- }
- public Box(T value)
- {
- this.Value = value;
- }
- public T Value
- {
- get
- {
- return value;
- }
- set
- {
- this.value = value;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment