Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace struct_dictionary
- {
- class Dctnr {
- int num = 0;
- Dictionary<int, string> wishes = new Dictionary<int, string>();
- public void addingEl(string str) {
- num += 1;
- wishes.Add(num, str);
- }
- public void removingEl(int key) {
- if (key > 0)
- {
- wishes.Remove(key);
- }
- else {
- Console.WriteLine("You've written an inappropriate number");
- }
- }
- public void showingEl() {
- foreach (int i in wishes.Keys) {
- Console.WriteLine(i + " " + wishes[i]);
- }
- }
- public void countingEl() {
- int count = wishes.Count();
- Console.WriteLine(count);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine("The dictionary of wishes");
- Console.ResetColor();
- Console.WriteLine("Please enter an appropriate number where:" +
- "\n 1 - adding one new element to the dictionary;" +
- "\n 2 - removing one element from the dictionary;" +
- "\n 3 - showing all the elements of the dictionary;" +
- "\n 4 - counting all the elements of the dictionary.");
- Dctnr dctnr = new Dctnr();
- while (true)
- {
- int choice = Convert.ToInt32(Console.ReadLine());
- switch (choice)
- {
- case 1:
- Console.WriteLine("Please, input the new wish");
- dctnr.addingEl(Console.ReadLine());
- break;
- case 2:
- Console.WriteLine("Please, input the number of the wish");
- dctnr.removingEl(Convert.ToInt32(Console.ReadLine()));
- break;
- case 3:
- dctnr.showingEl();
- break;
- case 4:
- dctnr.countingEl();
- break;
- default:
- Console.WriteLine("unknown command; try again");
- break;
- }
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement