如何比较具有类似性质的两种明显不同的对象

编程入门 行业动态 更新时间:2024-10-14 00:28:25
本文介绍了如何比较具有类似性质的两种明显不同的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是所有在C#中使用.NET 2.0。

This is all in C#, using .NET 2.0.

我有对象的两个列表。他们不是相关的对象,但他们确实有一些事情在常见的,可以作为一个基于GUID唯一标识进行比较这样。这两个列表需要由只包含的GUID另一个列表可能会或可能不会匹配过滤编号的包含在第一两个列表。

I have two lists of objects. They are not related objects, but they do have certain things in common that can be compared such as a Guid based unique identifer. These two lists need be filtered by another list which just contains Guid's which may or may not match up with the ID's contained in the first two lists.

我曾经想过铸造每个对象名单只是对象,并通过排序的想法这一点,但我不知道,我就可以,一旦它投来访问ID属性,我认为该方法的两个列表进行排序应该是在明知有些哑了什么进行排序名单。

I have thought about the idea of casting each object list to just 'object' and sorting by that, but I'm not sure that I'll be able to access the ID property once it's cast, and I'm thinking that the method to sort the two lists should be somewhat dumb in knowing what the list to be sorted is.

什么会在每个对象列表带来最好的方式,以便它可以针对仅与列表进行排序的ID

What would be the best way to bring in each object list so that it can be sorted against the list with only the ID's?

推荐答案

您应该让您的每一个不同的对象实现共同的接口。然后创建一个IComparer的< T>该接口并在排序使用它

You should make each of your different objects implement a common interface. Then create an IComparer<T> for that interface and use it in your sort.

更多推荐

如何比较具有类似性质的两种明显不同的对象

本文发布于:2023-11-30 16:04:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两种   性质   类似   对象

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!