本文介绍了如何删除一列,并从C#锯齿状排阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下dists中的锯齿形阵列

  INT [] [] dists中=新的INT [] [] 
{
新INT [] {0,2,3,5,2},
新INT [] {2,0,1,3,5},
新INT [] {3,1,0,4,4},
新INT [] {5,3,4,0,2},
新INT [] {2,5,4,2 ,0}
};

现在我想创建名为 finalDists 当我从 dists中的原始数组中删除第3行3列。我的意思是我想终于有如下交错数组:

  INT [] [] finalDists =新INT [] [] 
{
新INT [] {0,2,5,2},
新INT [] {2,0,3,5},
新INT [] {5,3 ,0,2},
新INT [] {2,5,2,0}
};



我很困惑如何处理这个问题,所有的感谢您的帮助之前


解决方案

  INT [] [] = finalDists dists.Where((ARR,I)=>!I = 2)//跳过一行3#
。选择(ARR => arr.Where((项目,I)=>!I = 2)//跳过山口3#
.ToArray() )
.ToArray();


I have following jagged array of "dists"

int[][] dists = new int[][]
{
    new int[]{0,2,3,5,2},
    new int[]{2,0,1,3,5},
    new int[]{3,1,0,4,4},
    new int[]{5,3,4,0,2},
    new int[]{2,5,4,2,0}
};

now I want to create another jagged array named as finalDists when I remove the 3rd row and 3rd column from original array of dists. I mean I want finally have following jagged array:

int[][] finalDists = new int[][]
{
    new int[]{0,2,5,2},
    new int[]{2,0,3,5},
    new int[]{5,3,0,2},
    new int[]{2,5,2,0}
}; 

I am confused how to handle this issue, before all thanks for your help

解决方案
int[][] finalDists = dists.Where((arr, i)=>i!=2) //skip row#3
                          .Select(arr=>arr.Where((item,i)=>i!=2) //skip col#3
                                          .ToArray())
                          .ToArray();

这篇关于如何删除一列,并从C#锯齿状排阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 22:53