Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,855 questions

51,776 answers

573 users

How to create a simple phone book with dictionary in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
 
namespace ConsoleApplication1
{
    public delegate void mydelegate();

    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, long> phonebook = new Dictionary<string, long>();

            phonebook.Add("Tom", 1234567);
            phonebook.Add("Emma", 9865764);

            phonebook["Ava"] = 6487291;

            foreach (KeyValuePair<string, long> keyval in phonebook)
            {
                Console.WriteLine("{0} - {1}", keyval.Key, keyval.Value);
            }

            if (phonebook.ContainsKey("Ava"))
            {
                Console.WriteLine("\nAva phone number: " + phonebook["Ava"]);
            }
            Console.WriteLine("\nTotal numbers: " + phonebook.Count);

            phonebook.Remove("Ava");
            Console.WriteLine("\nAfter Remove - Total numbers: " + phonebook.Count);
            foreach (KeyValuePair<string, long> keyval in phonebook)
            {
                Console.WriteLine("{0} - {1}", keyval.Key, keyval.Value);
            }
        }
    }
}

/*
run:
     
Tom - 1234567
Emma - 9865764
Ava - 6487291

Ava phone number: 6487291

Total numbers: 3

After Remove - Total numbers: 2
Tom - 1234567
Emma - 9865764
        
*/

 



answered Apr 24, 2017 by avibootz
edited Apr 24, 2017 by avibootz

Related questions

...