multikey dictionary
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace mtest2
{
class Config
{
public class Item : IEquatable<Item>
{
private readonly string _X;
private readonly string _Y;
public Item(string x, string y)
{
_X = x;
_Y = y;
}
public string X
{
get { return _X; }
}
public string Y
{
get { return _Y; }
}
public override int GetHashCode()
{
return _X.GetHashCode() ^ _Y.GetHashCode();
}
public bool Equals(Item other)
{
if (_X != other._X)
return false;
return _Y == other._Y;
}
}
}
}
// tuple 이용하기 .net 4.0 이상 조오타~~~
//-----------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace mtest2
{
class Program
{
static void Main(string[] args)
{
Dictionary<Tuple<string, string>, string> dicReloadedItems = new Dictionary<Tuple<string, string>, string>();
Dictionary<Tuple<string, string>, string> dicCurrentItems = new Dictionary<Tuple<string, string>, string>();
dicReloadedItems.Add(new Tuple<string, string>("1key", "1value"), "dic.1value");
dicReloadedItems.Add(new Tuple<string, string>("2key", "2value"), "dic.2value");
dicReloadedItems.Add(new Tuple<string, string>("3key", "3value"), "dic.3value");
dicCurrentItems.Add(new Tuple<string, string>("3key", "3value"), "dic.3value");
dicCurrentItems.Add(new Tuple<string, string>("4key", "4value"), "dic.4value");
foreach (var dicReloadedItem in dicReloadedItems)
{
if (!dicCurrentItems.ContainsKey(dicReloadedItem.Key))
{
Console.WriteLine(string.Format("a{0}, {1}", dicReloadedItem.Key.Item1, dicReloadedItem.Key.Item2));
}
}
Console.ReadKey();
}
}
}