110,561
社区成员
发帖
与我相关
我的任务
分享
foreach (var o in b)
{
double v;
if (a.TryGetValue(o.Key, out v))
{
if (o.Value != v) Console.WriteLine("改变: {0} {1}", o.Key, o.Value - v);
}
else Console.WriteLine("新增: {0} {1}", o.Key, o.Value);
}
荔枝 就犒劳你了 var a = new Dictionary<double,double>()
{
{98.9, 6.6},
{90.5, 675.2},
{85.8, 562},
{76.7, 45.8},
{70.9, 45.8},
};
var b = new Dictionary<double,double>()
{
{98.9, 6.6},
{91.8, 50},
{90.5, 375.2},
{87.8, 88.88},
{85.8, 562},
{70.9, 45.8},
};
foreach (var o in b)
{
if (!a.ContainsKey(o.Key)) Console.WriteLine("新增: {0} {1}", o.Key, o.Value);
else
{
double v;
a.TryGetValue(o.Key, out v);
if (o.Value != v) Console.WriteLine("改变: {0} {1}", o.Key, o.Value - v);
}
}
foreach (var o in a)
{
if (!b.ContainsKey(o.Key)) Console.WriteLine("消失: {0} {1}", o.Key, o.Value);
}
var a = new double[,]
{
{98.9, 6.6},
{90.5, 675.2},
{85.8, 562},
{76.7, 45.8},
{70.9, 45.8},
};
var b = new double[,]
{
{98.9, 6.6},
{91.8, 50},
{90.5, 375.2},
{87.8, 88.88},
{85.8, 562},
{70.9, 45.8},
};
int i = 0;
int j = 0;
while(i < b.Length / 2)
{
if (j >= a.Length || b[i, 0] > a[j, 0])
{
Console.WriteLine("新增 {0} {1}", b[i, 0], b[i, 1]);
j--;
}
else if (b[i, 0] == a[j, 0])
{
if (b[i, 1] != a[j, 1])
{
Console.WriteLine("改变 {0} {1}", b[i, 0], b[i, 1] - a[j, 1]);
}
}
else if (b[i, 0] < a[j, 0])
{
Console.WriteLine("消失 {0} {1}", a[j, 0], a[j, 1]);
j++;
}
i++;
j++;
}