Beispiel #1
0
        int IComparer.Compare(object ob1, object ob2)
        {
            AbstrState s1 = (AbstrState)ob1;
            AbstrState s2 = (AbstrState)ob2;

            return String.Compare(s1.Name, s2.Name);
        }
Beispiel #2
0
        int IComparer.Compare(object ob1, object ob2)
        {
            AbstrState s1 = (AbstrState)ob1;
            AbstrState s2 = (AbstrState)ob2;

            return String.Compare(s1.Continent, s2.Continent);
        }
Beispiel #3
0
        // Function to add an element.
        public static void AddElem(ref MyDictionary <int, AbstrState> myDictionary)
        {
            AbstrState state = ObjectInput();

            myDictionary.Add(state.Name.Length, state);

            Console.WriteLine("The element is successfully added!\nPress ENTER to continue");
            Console.ReadLine();
        }
Beispiel #4
0
        int IComparer.Compare(object ob1, object ob2)
        {
            AbstrState s1 = (AbstrState)ob1;
            AbstrState s2 = (AbstrState)ob2;

            
           int index=String.Compare(s1.LeaderName, s2.LeaderName);
            return index;
        }
Beispiel #5
0
        // Redefenition of the Equals method (for == and != of DicPoint).
        public override bool Equals(object ob)
        {
            AbstrState buf = (AbstrState)ob;
            bool equal = false;

            if (Name == buf.Name && LeaderName == buf.LeaderName &&
                Population == buf.Population && Age == buf.Age && Continent == buf.Continent)
                equal = true;

            return equal;
        }
Beispiel #6
0
 // Redefinition of the CompareTo method from the IComparable interface.
 public int CompareTo(object s)
 {
     AbstrState newS = s as AbstrState;
     int result = new int();
     if (this.Population == newS.Population)
         result = 0;
     if (this.Population > newS.Population)
         result = 1;
     if (this.Population < newS.Population)
         result = -1;
     return result;
 }
Beispiel #7
0
        int IComparer.Compare(object ob1, object ob2)
        {
            AbstrState s1 = (AbstrState)ob1;
            AbstrState s2 = (AbstrState)ob2;

            int result = new int();
            if (s1.Age == s2.Age)
                result = 0;
            if (s1.Age > s2.Age)
                result = 1;
            if (s1.Age < s2.Age)
                result = -1;
            return result;
        }
Beispiel #8
0
        // Function to fill the dictionary.
        public static void FillDic(ref MyDictionary <int, AbstrState> myDictionary)
        {
            // Getting the count.
            int count = CountInput();

            for (int i = 0; i < count; i++)
            {
                AbstrState random = RandomState();

                // The key is a state's name length.
                myDictionary.Add(random.Name.Length, random);
            }

            Console.WriteLine("The dictionary has been successfully filled with random values!\nPress ENTER to continue");
            Console.ReadLine();
        }
Beispiel #9
0
        // Function to remove an object.
        public static void RemoveFromDic(ref MyDictionary <int, AbstrState> myDictionary)
        {
            Console.Clear();

            AbstrState buf = ObjectInput();

            bool ok = myDictionary.Remove(buf);

            if (ok)
            {
                Console.WriteLine("The element is removed!\nPress ENTER to continue");
            }
            else
            {
                Console.WriteLine("There is no element with this value\nPress ENTER to continue");
            }

            Console.ReadLine();
        }
Beispiel #10
0
        // Function to check a value.
        public static void CheckValue(MyDictionary <int, AbstrState> myDictionary)
        {
            Console.Clear();

            // Enter the value.
            AbstrState abstrState = ObjectInput();

            bool ok = myDictionary.ContainsValue(abstrState);

            if (ok)
            {
                Console.WriteLine("There is an element with this value!");
            }
            else
            {
                Console.WriteLine("There is no element with this value");
            }

            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();
        }
Beispiel #11
0
 int IComparer.Compare(object ob1, object ob2)
 {
     AbstrState s1 = (AbstrState)ob1;
     AbstrState s2 = (AbstrState)ob2;
     return s1.CompareTo(s2);
 }