NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace ConsoleApp1
{
public class Class4
{
Hashtable h = new Hashtable();
//public Class4()
//{
// h = new Hashtable();
//}
public void add(dynamic key, dynamic value)
{
if (h.ContainsKey(key))
{
throw new Exception("key already present");
}
h.Add(key, value);
}
public string search(dynamic key)
{
if (!h.ContainsKey(key))
{
throw new Exception("key not present");
}
return h[key];
}
public void deleteit(dynamic key)
{
if (!h.ContainsKey(key))
{
throw new Exception("key not present to be deleted");
}
h.Remove(key);
}
public void print()
{
var key = h.Keys;
if (h.Count == 0)
{
Console.WriteLine("empty");
}
foreach (var item in key)
{
Console.WriteLine($"Mobile number : {item} nname : {h[item]}");
}
}
public void edit(dynamic key, dynamic value)
{
if (!h.ContainsKey(key))
{
throw new Exception("key not present");
}
else
{
h[key] = value;
}
}
}
}






private static Class4 c = new Class4();
static void Main(string[] args)
{
bool b = true;

while (b)
{
Console.WriteLine("1.addn2.Searchn3.deleten4.editn5.print all");
Console.WriteLine("Enter any option form [1-5]");
int ch = Convert.ToInt16(Console.ReadLine());
Console.Clear();
switch (ch)
{
case 1:
add();
break;
case 2:
search();
break;
case 3:
deleteit();
break;
case 4:
edit();
break;
case 5:
printall();
break;
default:
Invalid();
break;

}
Console.Clear();
Console.WriteLine("Enter "y" to continue");
var read1 = Console.ReadLine();
if (read1 != "y")
b = false;
Console.Clear();

}


}

private static void edit()
{
Console.WriteLine("Enter mobile number");
var mob = Console.ReadLine();
int flag = 0;
try
{
c.search(mob);
}
catch (Exception e)
{
Console.Clear();
Console.WriteLine(e.Message);
flag = 1;
}
if (flag == 0)
{
Console.WriteLine("Enter the new name associated with mobile number");
var name = Console.ReadLine();
Console.Clear();
try
{
c.edit(mob, name);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
flag = 1;
}
if (flag == 0)
{
Console.Clear();
Console.WriteLine("Modified sucessfully");
}
}
System.Threading.Thread.Sleep(2000);

}

private static void deleteit()
{
Console.WriteLine("Enter mobile number to search the record");
var mob1 = Console.ReadLine();
dynamic a = "";
int flag = 0;
try
{
c.deleteit(mob1);
}
catch (Exception e)
{
Console.Clear();
Console.WriteLine(e.Message);
flag = 1;
}
if (flag == 0)
{
Console.Clear();
Console.WriteLine("Deleted sucessfully");
}
System.Threading.Thread.Sleep(2000);
}

private static void Invalid()
{
Console.WriteLine("Enter valid options from 1 to 5.");
System.Threading.Thread.Sleep(2000);
}

private static void add()
{
Console.WriteLine("Enter mobile number");
var mob = Console.ReadLine();
Console.WriteLine("Enter name");
var name = Console.ReadLine();
Console.Clear();
int flag = 0;
try
{
c.add(mob, name);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
System.Threading.Thread.Sleep(2000);
flag = 1;
}
if (flag == 0)
{
Console.WriteLine("Added sucessfully");
}
System.Threading.Thread.Sleep(2000);
}
private static void search()
{
Console.WriteLine("Enter mobile number to search the record");
var mob1 = Console.ReadLine();
dynamic a = "";
int flag = 0;
try
{
a = c.search(mob1);
}
catch (Exception e)
{
Console.Clear();
Console.WriteLine(e.Message);
flag = 1;
}
if (flag == 0)
{
Console.Clear();
Console.WriteLine($"Name associated with the key {mob1} : {a}");
}
System.Threading.Thread.Sleep(2000);
}
private static void printall()
{
c.print();
System.Threading.Thread.Sleep(2000);
}



     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.