所以在我的程序中,我有一个包含1000个票据对象的列表。每个对象都有一个int ID和6个数字的int SortedSet。我希望用户能够输入6个数字,并将这6个数字与列表中1000个对象中每一个排序集合中的6个数字进行比较。如果数字匹配,我希望输出对象的ID。实现这一目标的最佳途径是什么?我是否也应该将用户输入的6个数字放入SortedSet中?这就是我想要做的。如果是这样,我将如何将SortedSet与列表中的1000个SortedSets中的每个SortedSets进行比较?我已经为这个工作了两天了,我的头都炸坏了!
希望这是合理的!
发布于 2016-02-19 22:49:11
是的,继续将用户编号放入SortedSet中,然后您可以使用以下方法查看票证列表中的集合是否与带有用户条目的集合相等。
SortedSet<int>.CreateSetComparer().Equals(userSet, objectSet);要获得ID列表,您可以这样做。
IEnumerable<int> GetMatchingSetIDs(SortedSet<int> userSet)
{
IEqualityComparer<SortedSet<int>> setComparer = SortedSet<int>.CreateSetComparer();
foreach (Ticket ticket in tickets) //Where ticket is your ticket class with the sortedsets and tickets is a List of tickets.
{
if (setComparer.Equals(ticket.Set, userSet))
{
yield return ticket.ID;
}
}
}发布于 2016-02-20 00:05:00
如果我正确地理解了你,那么你需要的是一个十字路口。
int[] array1 = { 1, 2, 3 };
int[] array2 = { 2, 3, 4 };
// Call Intersect extension method.
var intersect = array1.Intersect(array2);
// Write intersection to screen.
foreach (int value in intersect)
{
Console.WriteLine(value);
}发布于 2021-10-20 15:50:36
您可以使用SortedSet.SetEquals()方法。
https://learn.microsoft.com/en-US/dotnet/api/system.collections.generic.sortedset-1.setequals
https://stackoverflow.com/questions/35516275
复制相似问题