这是所有在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.