internal class Program
{
static Dictionary<string, List<KeyValuePair<string, string>>> db = new Dictionary<string, List<KeyValuePair<string, string>>>();
static void Main2(string[] args)
{
AddToDb("A", "B", "C");
AddToDb("A", "D", "E");
AddToDb("I", "J", "K");
AddToDb("I", "L", "M");
RemoveFromDb("A", "B");
RemoveFromDb("I", "J");
Console.WriteLine(db.Count);
}
private static bool RemoveFromDb(string key, string fieldKey)
{
if (!db.ContainsKey(key))
{
return false;
}
else
{
var items = db[key];
foreach (var item in items)
{
if (item.Key == fieldKey)
{
items.Remove(item);
return true;
}
}
}
return false;
}
private static void AddToDb(string key, string fieldkey, string fieldValue)
{
if (db.ContainsKey(key))
{
var list = db[key];
var kvp = new KeyValuePair<string, string>(fieldkey, fieldValue);
list.Add(kvp);
}
else
{
var list = new List<KeyValuePair<string, string>>();
var kvp = new KeyValuePair<string, string>(fieldkey, fieldValue);
list.Add(kvp);
db.Add(key, list);
}
}
}
No comments:
Post a Comment