Reputation: 815
I need to test if two cells are equal using closedxml and this is the very basic code that I am using:
if ((PipeSheet.Cell(j, 3).Value == SheetToEdit.Cell(i, RegionCodeInMain).Value))
However, it is not working. I put in a break point with a watch for each side, even when they were equal it was still evaluating to false.
PipeSheet
and SheetToEdit
along with i
and j
are variables I set.
What do I need to do differently?
Upvotes: 1
Views: 410
Reputation: 17550
The Value
property returns an object, which means your program checks for reference equality, not value equality. Depending on the data type for the values use something like this:
if ((PipeSheet.Cell(j, 3).GetValue<int>() == SheetToEdit.Cell(i, RegionCodeInMain).GetValue<int>()))
or
if ((PipeSheet.Cell(j, 3).GetValue<string>() == SheetToEdit.Cell(i, RegionCodeInMain).GetValue<string>()))
Upvotes: 1