Exemplo n.º 1
0
        static Person Finder(ArraySet arrset, string id = null)
        {
            if (id == null)
            {
                id = numInput("\nEnter the ID of the record you want:");
            }

            Person person = new Person(id, "", "", 0, "", 0);

            if (arrset.Contains(person))
            {
                int bucket = Math.Abs(person.GetHashCode()) % arrset.Buckets;

                int pos = arrset.BinarySearch(person);

                if (arrset.ArrSet[bucket][pos] != null)
                {
                    person = arrset.ArrSet[bucket][pos];
                    Console.WriteLine(person);
                }
            }

            else
            {
                person.Id = "";

                Console.WriteLine("That record doesn't exist.");
            }

            return(person);

            /* foreach (var item in Person)
             * {
             *
             *  if (item.Id == id)
             *  {
             *
             *      person = item;
             *      Console.WriteLine(person);
             *
             *  }
             *
             * }
             *
             * if (person.Id == "") Console.WriteLine("That record doesn't exist.");
             *
             * return person; */
        }