我有一个带有维度的 int 数组:
int[,] intArray2D = new int[3,3];
我想有两种方法,例如:
int[,] removeLine(int[,] array, int arrayColumnsCount, int lineToRemove){...}
int[,] removeColumn(int[,] array, int arrayColumnsCount, int columnToRemove){...}
所以,有了数组:
1 2 3
4 5 6
7 8 9
使用 lineToRemove = 1 调用 removeLine 方法我必须获取数组:
1 2 3
7 8 9
使用 columnToRemove = 1 调用 columnLine 方法我必须获取数组:
1 3
4 6
7 9
您的实现建议是什么?
谢谢
转发
最佳答案
因为数组不适用于添加和删除项目的情况,所以您应该使用更合适的数据结构。
LinkedList当您期望在列表的中间或开头会有很多添加和删除时,它是最好的选择。
当您只在末尾添加和删除列表时,列表工作正常。
您可以通过导入来使用它:
using System.Collections.Generic;
和编码:
LinkedList<LinkedList<int>> grid = new LinkedList<LinkedList<int>>()
grid.Add(new LinkedList<int>()); //repeat for each column / row
关于c# - 如何删除二维数组中的一行和一列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2156195/