示例#1
0
        static void Main()
        {
            var distances = new BiDictionary <string, string, int>();

            distances.Add("Sofia", "Varna", 443);
            distances.Add("Sofia", "Varna", 468);
            distances.Add("Sofia", "Varna", 490);
            distances.Add("Sofia", "Plovdiv", 145);
            distances.Add("Sofia", "Bourgas", 383);
            distances.Add("Plovdiv", "Bourgas", 253);
            distances.Add("Plovdiv", "Bourgas", 292);

            var distancesFromSofia      = distances.FindByKey1("Sofia");        // [443, 468, 490, 145, 383]
            var distancesToBourgas      = distances.FindByKey2("Bourgas");      // [383, 253, 292]
            var distancesPlovdivBourgas = distances.Find("Plovdiv", "Bourgas"); // [253, 292]
            var distancesRousseVarna    = distances.Find("Rousse", "Varna");    // []
            var distancesSofiaVarna     = distances.Find("Sofia", "Varna");     // [443, 468, 490]
            var remove = distances.Remove("Sofia", "Varna");                    // true
            var distancesFromSofiaAgain  = distances.FindByKey1("Sofia");       // [145, 383]
            var distancesToVarna         = distances.FindByKey2("Varna");       // []
            var distancesSofiaVarnaAgain = distances.Find("Sofia", "Varna");    // []

            Console.WriteLine(string.Join(", ", distancesFromSofia));
            Console.WriteLine(string.Join(", ", distancesToBourgas));
            Console.WriteLine(string.Join(", ", distancesPlovdivBourgas));
            Console.WriteLine(string.Join(", ", distancesRousseVarna));
            Console.WriteLine(string.Join(", ", distancesSofiaVarna));
            Console.WriteLine(remove);
            Console.WriteLine(string.Join(", ", distancesFromSofiaAgain));
            Console.WriteLine(string.Join(", ", distancesToVarna));
            Console.WriteLine(string.Join(", ", distancesSofiaVarnaAgain));
        }
示例#2
0
        private static void Main()
        {
            var distances = new BiDictionary <string, string, int>();

            distances.Add("Sofia", "Varna", 443);
            distances.Add("Sofia", "Varna", 468);
            distances.Add("Sofia", "Varna", 490);
            distances.Add("Sofia", "Plovdiv", 145);
            distances.Add("Sofia", "Bourgas", 383);
            distances.Add("Plovdiv", "Bourgas", 253);
            distances.Add("Plovdiv", "Bourgas", 292);

            var distancesFromSofia = distances.FindByKey1("Sofia");

            PrintDistances(distancesFromSofia);

            var distancesToBourgas = distances.FindByKey2("Bourgas");

            PrintDistances(distancesToBourgas);

            var distancesPlovdivBourgas = distances.Find("Plovdiv", "Bourgas");

            PrintDistances(distancesPlovdivBourgas);

            var distancesRousseVarna = distances.Find("Rousse", "Varna");

            PrintDistances(distancesRousseVarna);

            var distancesSofiaVarna = distances.Find("Sofia", "Varna");

            PrintDistances(distancesSofiaVarna);

            Console.WriteLine(distances.Remove("Sofia", "Varna"));

            var distancesFromSofiaAgain = distances.FindByKey1("Sofia");

            PrintDistances(distancesFromSofiaAgain);

            var distancesToVarna = distances.FindByKey2("Varna");

            PrintDistances(distancesToVarna);

            var distancesSofiaVarnaAgain = distances.Find("Sofia", "Varna");

            PrintDistances(distancesSofiaVarnaAgain);

            Console.WriteLine(distances.Remove("Sofia", "Lovech"));
        }