-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyIDictionary.cs
50 lines (42 loc) · 1.22 KB
/
MyIDictionary.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using Exceptions;
namespace LabCsharp
{
public interface MyIDictionary<K,V>
{
void add(K key, V value);
void update(K key,V value);
V lookup(K key);
int isDefined(K key);
string ToString();
}
public class MyDictionary<K, V> : MyIDictionary<K, V>
{
private Dictionary<K, V> dict;
public MyDictionary() { dict = new Dictionary<K,V>();}
public void add(K key, V value) {dict.Add(key,value);}
public void update(K key, V value) { dict[key] = value; }
public V lookup(K key)
{
if (dict.ContainsKey(key))
return dict[key];
else
throw new DictExceptions("The key does not exist!!! \n");
}
public override string ToString()
{
string str = null;
foreach (var item in dict)
str = str +item.Key+"->"+item.Value+'\n';
return str;
}
public int isDefined(K key)
{
if (dict.ContainsKey(key))
return 1;
else
return 0;
}
}
}