コード例 #1
0
        public void PutNumber(string name, string number)
        {
            if (name == null || number == null)
            {
                throw new Exception("name and number cannot be null");
            }
            var i = Find(name);

            if (i >= 0)
            {
                _data[i].number = number;
            }
            else
            {
                if (_dataCount == _data.Length)
                {
                    Array.Resize(ref _data, (2 * _data.Length));
                }

                var newEntry = new PhoneEntry {
                    name = name, number = number
                };                              // Create a new pair.
                _data[_dataCount] = newEntry;   // Add the new pair to the array.
                _dataCount++;
            }
        }
コード例 #2
0
        /*public string GetNumber(string name)
         * {
         *  var position = Find(name);
         *  if (position == -1)
         *  {
         *      return null;
         *  }
         *  else
         *  {
         *      return _data[position].number;
         *  }
         * }*/

        public void PutNumber(string name, string number)
        {
            if (name == null || number == null)
            {
                throw new Exception("name and number cannot be null");
            }

            var i = Find(name);

            if (i >= 0)
            {
                phoneDictionary[number] = number;
            }
            var newEntry = new PhoneEntry()
            {
                name = name, number = number
            };

            phoneDictionary.Add(name, number);
            _dataCount++;
        }
コード例 #3
0
        public string PutNumber(string name, string number)
        {
            if (name == null || number == null)
            {
                throw new Exception("name and number cannot be null");
            }
            var i = Find(name);

            if (i >= 0)
            {
                _data[i].number = number;
                return("updated");
            }
            else
            {
                var newEntry = new PhoneEntry {
                    name = name, number = number
                };                                 // Create a new pair.
                _data.Add(_dataCount, newEntry);   // Add the new pair to the array.
                _dataCount++;
                return("created");
            }
        }