AI编程助手
AI免费问答

如何在C#中将一个二维数组转换为一维数组?

王林   2023-09-20 16:01   2300浏览 转载

如何在c#中将一个二维数组转换为一维数组?

设置一个二维数组和一个一维数组 −

int[,] a = new int[2, 2] {{1,2}, {3,4} };
int[] b = new int[4];

将2D数组转换为1D数组,将之前声明的二维数组设置为一维数组 −

for (i = 0; i <p>以下是将二维数组转换为一维数组的完整代码示例:</p><h2>示例</h2><pre class="brush:php;toolbar:false;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Program {
   class twodmatrix {

      static void Main(string[] args) {
      int[, ] a = new int[2, 2] {
         {
            1,
            2
         },{
            3,
            4
            }
         };

         int i, j;
         int[] b = new int[4];
         int k = 0;

         Console.WriteLine("Two-Dimensional Array...");
         for (i = 0; i 
声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除