Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace HashDictionary
  5. {
  6.     class MainClass
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             var location = new GeoLocation();
  11.             var city = new City();
  12.  
  13.             Console.WriteLine("Choose what you want to do:\n1. Run test on hashtable.\n2. Search for a city.");
  14.            
  15.             switch (Console.ReadKey(false).Key)
  16.             {
  17.                 case ConsoleKey.D1:
  18.                     HashDictionary<int, int> d = new HashDictionary<int, int>(10000);
  19.                     HashtableTester.TestDriver.Instance.Run(d, 10000);
  20.                     Console.ReadKey();
  21.                     break;
  22.  
  23.                 case ConsoleKey.D2:
  24.                     HashDictionary<GeoLocation, City> e = new HashDictionary<GeoLocation, City>(10000);
  25.  
  26.                     const string f = "cities100000.txt";
  27.  
  28.                     using (StreamReader r = new StreamReader(f))
  29.                     {
  30.                         var lines = File.ReadAllLines(f);
  31.                         foreach (var line in lines)
  32.                         {
  33.                             var words = line.Split('\t');
  34.                             var cityHolder = city.Add(words[0], words[3]);
  35.                             var locationHolder = location.Add(words[1], words[2]);
  36.  
  37.                             e.Add(locationHolder, cityHolder);
  38.                            
  39.                         }
  40.  
  41.                     }
  42.                     Console.WriteLine("\nEnter a latitude:");
  43.                     string latitude = Console.ReadLine();
  44.  
  45.                     Console.WriteLine("Enter a longitude:");
  46.                     string longitude = Console.ReadLine();
  47.  
  48.                     var RequestedKey = location.Add(latitude, longitude);
  49.                     if (e.ContainsKey(RequestedKey))
  50.                     {
  51.                         City RequestedCity;
  52.                         e.TryGetValue(RequestedKey, out RequestedCity);
  53.                         Console.WriteLine(RequestedCity.Name);
  54.                         Console.WriteLine(RequestedCity.Population);
  55.                         Console.ReadLine();
  56.                     }
  57.                     break;
  58.             }
  59.            
  60.            
  61.  
  62.            
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement