public void Add(Name name, PhoneNumber number) { enlargeIfFull(); this.names[used] = name; this.phoneNumbers[used] = number; this.used++; }
private void findPhoneClick(object sender, RoutedEventArgs e) { string text = name.Text; if (!String.IsNullOrEmpty(text)) { Name personsName = new Name(text); PhoneNumber personsPhoneNumber = this.phoneBook[personsName]; phoneNumber.Text = personsPhoneNumber.Text; } }
private void findByNameClick(object sender, RoutedEventArgs e) { // TODO: string text = name.Text; if (!String.IsNullOrEmpty(text)) { Name personName = new Name(text); PhoneNumber personPhoneNumber = this.phoneBook[personName]; phoneNumber.Text = String.IsNullOrEmpty(personPhoneNumber.Text) ? "Not Found" : personPhoneNumber.Text; } }
// TODO: write 2nd indexer here public PhoneNumber this[Name name] { get { int i = Array.IndexOf(this.names, name); if (i != -1) { return this.phoneNumbers[i]; } else { return new PhoneNumber(); } } }
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; } }