以下示例场景:
A
我有 RowIndex为
4
ColumnIndex 为 7 的列
我想将列A
向左移动 11 位,因此我得到的列索引 ( B
) 为
RowIndex: 2
ColumnIndex: 6
更糟糕的是,该表是一个子表,因此不是从索引 0, 0 开始,而是像本例中的 4, 2 这样的索引开始
我很确定这可以通过模计算来解决,但我的大脑拒绝给我正确的公式。
到目前为止,我已经使用 C# 开始编写此代码,但这显然不正确(https://dotnetfiddle.net/5iEqgD):
public static void Main()
{
int minColumnIndex = 4;
int maxColumnIndex = 8;
int minRowIndex = 2;
int maxRowIndex = 5;
int cellARowIndex = 4;
int cellAColumnIndex = 7;
int shiftCellToTheLeft = 11;
int cellBColumnIndex = cellAColumnIndex - ((maxColumnIndex - minColumnIndex + 1) % shiftCellToTheLeft);
int cellBRowIndex = cellARowIndex - ((maxColumnIndex - maxColumnIndex + 1) % shiftCellToTheLeft);
Console.WriteLine("cellBColumnIndex: " + cellBColumnIndex);
Console.WriteLine("cellBRowIndex: " + cellBRowIndex);
// Result:
// cellBColumnIndex: 2
// cellBRowIndex: 3
}
我在这里做错了什么?