-Annie-

GenericCountMethodDouble

Jul 19th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. namespace GenericCountMethodDouble
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class GenericCountMethodDouble
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<Box<double>> boxes = new List<Box<double>>();
  12.  
  13.             int boxCount = Int32.Parse(Console.ReadLine());
  14.  
  15.             for (int i = 0; i < boxCount; i++)
  16.             {
  17.                 boxes.Add(new Box<double>(double.Parse(Console.ReadLine())));
  18.             }
  19.  
  20.             Box<double> comparableBox = new Box<double>(double.Parse(Console.ReadLine()));
  21.  
  22.             int countOfGreaterelements = CompareElements(boxes, comparableBox);
  23.             Console.WriteLine(countOfGreaterelements);
  24.         }
  25.  
  26.         static int CompareElements<T>(List<Box<T>> boxes, Box<T> comparableBox)
  27.             where T : IComparable<T>
  28.         {
  29.             int count = boxes.Count(b => b.Value.CompareTo(comparableBox.Value) > 0);
  30.  
  31.             return count;
  32.         }
  33.     }
  34.  
  35.     public class Box<T> where T : IComparable<T>
  36.     {
  37.         private T value;
  38.  
  39.         public Box()
  40.             : this(default(T))
  41.         {
  42.         }
  43.  
  44.         public Box(T value)
  45.         {
  46.             this.Value = value;
  47.         }
  48.  
  49.         public T Value
  50.         {
  51.             get
  52.             {
  53.                 return value;
  54.             }
  55.  
  56.             set
  57.             {
  58.                 this.value = value;
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment