public void Add(Name name, PhoneNumber number)
 {
     enlargeIfFull();
     this.names[used] = name;
     this.phoneNumbers[used] = number;
     this.used++;
 }
示例#2
0
 private void findByPhoneNumberClick(object sender, RoutedEventArgs e)
 {
     // TODO:
     string text = phoneNumber.Text;
     if (!String.IsNullOrEmpty(text)) {
         PhoneNumber personPhoneNumber = new PhoneNumber(text);
         Name personName = this.phoneBook[personPhoneNumber];
         name.Text = String.IsNullOrEmpty(personName.Text) ? "Not Found" : personName.Text;
     }
 }
示例#3
0
 private void findNameClick(object sender, RoutedEventArgs e)
 {
     string text = phoneNumber.Text;
     if (!String.IsNullOrEmpty(text))
     {
         PhoneNumber personsPhoneNumber = new PhoneNumber(text);
         Name personsName = this.phoneBook[personsPhoneNumber];
         name.Text = personsName.Text;
     }
 }
示例#4
0
		// TODO: write 1st indexer here
        public Name this[PhoneNumber number]
        {
            get{
                int i = Array.IndexOf(this.phoneNumbers, number);
                if (i != -1)
                {
                    return this.names[i];
                }
                else {
                    return new Name();
                }
            }
        }
        private void enlargeIfFull()
        {
            if (this.used == this.names.Length)
            {
                int bigger = used + 16;

                Name[] moreNames = new Name[bigger];
                this.names.CopyTo(moreNames, 0);

                PhoneNumber[] morePhoneNumbers = new PhoneNumber[bigger];
                this.phoneNumbers.CopyTo(morePhoneNumbers, 0);

                this.names = moreNames;
                this.phoneNumbers = morePhoneNumbers;
            }
        }
示例#6
0
 public bool Equals(PhoneNumber other) => this.number == other.number;