比较2个在C#中的深嵌套词典的对象
我有一个深嵌套词典:
var a1 = new Dictionary<string, Dictionary<string, Dictionary<string, Person>>>();
var a2 = new Dictionary<string, Dictionary<string, Dictionary<string, Person>>>();
其中person
是一些数据结构,其中包含name
,family
,age> age
。 ..
public class Person
{
public string name{ get; set; }
public string family{ get; set; }
public int age { get; set; }
}
我想比较 A1和A2,尤其是Person的
成员之间。 最好的方法是什么?
I have a deep nested dictionaries:
var a1 = new Dictionary<string, Dictionary<string, Dictionary<string, Person>>>();
var a2 = new Dictionary<string, Dictionary<string, Dictionary<string, Person>>>();
where Person
is some data structure containing members like name
, family
, age
...
public class Person
{
public string name{ get; set; }
public string family{ get; set; }
public int age { get; set; }
}
I want to compare between
a1 and a2 and especially between the Person's
members.
What is the best way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可以认为,我可以将其视为对象的深度比较,而不是仅仅因为以通用方式来涵盖大多数用例的通用方式而不是一项琐碎的任务。对于您而言,特定的一个非常容易实现。您只需要在该比较字典上编写2种方法,而一个比较对象的字典:
此代码段不涵盖很多内容,但是您可以扩展其以匹配用例。
There is no out of the box solution that I can think of as deep comparison of objects is not given by libraries just because it is not a trivial task to define in a generic way that would cover most use cases. For you specific one it is fairly easy to implement. You just need to write 2 methods on that compares dictionaries and one that compares the objects:
there is a lot not covered by this code snippet but you can expand of it to match your use cases.