我有一个清单
List<FirstIterationCapacitors> FirstIteration = new List<FirstIterationCapacitors>(); // A set of Solution capacitors object
这是它的课
class FirstIterationCapacitors
{
public int Iteration { get; set; }
public int CapacitorALocation { get; set; }
public int CapacitorBLocation { get; set; }
public int CapacitorCLocation { get; set; }
}
现在我有第二个清单
List<PossibleSolutionCapacitors> PossibleSolution = new List<PossibleSolutionCapacitors>(); // Possible Solution capacitors object
这是它的类
class PossibleSolutionCapacitors
{
public int CapacitorALocation { get; set; }
public int CapacitorBLocation { get; set; }
public int CapacitorCLocation { get; set; }
}
对于可能解决方案中的给定行(即第 2 行),我需要查看是否
- 可能Solution.CapacitorALocation 不存在于FirstIteration.CapacitorALocation(等于迭代X)或FirstIteration.CapacitorBLocation(等于迭代X)或FirstIteration.CapacitorCLocation(等于迭代X)
或者
- PossibleSolution.CapacitorBLocation 不存在于 FirstIteration.CapacitorALocation(等于迭代 X)或 FirstIteration.CapacitorBLocation(等于迭代 X)或 FirstIteration.CapacitorCLocation(等于迭代 X)
或者
- 在FirstIteration.CapacitorALocation(等于迭代X)或FirstIteration.CapacitorBLocation(等于迭代X)或FirstIteration.CapacitorCLocation(等于迭代X)中不存在PossibleSolution.CapacitorCLocation
理想情况下,如果条件为真/假,则布尔值表示真假
这是我迄今为止尝试过的,但它不起作用
int D = 4; // The row i care about
int E = PossibleSolution[D].CapacitorALocation;
int F = PossibleSolution[D].CapacitorBLocation;
int G = PossibleSolution[D].CapacitorCLocation;
var fixedSet = new HashSet<int>() {E};
if (!FirstIteration.Any(x => fixedSet.SetEquals(new[] { x.CapacitorALocation, x.CapacitorBLocation, x.CapacitorCLocation })))
{
fixedSet = new HashSet<int>() {F};
if (!FirstIteration.Any(x => fixedSet.SetEquals(new[] { x.CapacitorALocation, x.CapacitorBLocation, x.CapacitorCLocation })))
{
fixedSet = new HashSet<int>() {G};
if (!FirstIteration.Any(x => fixedSet.SetEquals(new[] { x.CapacitorALocation, x.CapacitorBLocation, x.CapacitorCLocation })))
{
//Match does not exist so do some real work here ......
}
}
}
谢谢,达摩