将一维数组插入多维数组 [英] Insert one dimensional array into multidimensional array

查看:84
本文介绍了将一维数组插入多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将 4 个一维数组输入到 4x4 多维数组中的方法.

I'm looking for a way to input 4 one-dimensional arrays into a 4x4 multidimensional array.

在我花时间寻找这个的过程中,我发现使用锯齿状数组似乎要简单得多.但是,我觉得我遗漏了一些明显的东西,想寻求帮助.

In the time I've spent looking for this I've found that it seems much simpler to do with jagged arrays. However, I feel like I'm missing something obvious and would like to ask for help.

for (int x = 0; x <= 3; x++)
{
    //reads in 4 separate values e.g. A B C D
    unitReader = sr.ReadLine();  

    //creates a char array with 4 separate elements
    char[] line = unitReader.ToCharArray();

    //places that array into a bigger jagged array
    fullArray[x] = line; 

    //just to test that it's worked
    Console.WriteLine(fullArray[x]);
}

这就是我如何使用之前定义的锯齿状数组来做到这一点:

this is how I've been able to do it with the jagged array which is defined earlier as:

char[][] fullArray = new char[4][];

是否有类似的代码可以让我按行将值分配给多维数组,而无需执行 16 遍来分配单个元素?

Is there code similar to this that would allow me to assign values by line to a multidimensional array without having to do 16 passes to assign individual elements?

推荐答案

我认为您正在寻找 Buffer.BlockCopy()

有关详细信息,请参阅 BufferCopy.BlockCopy 的文档

For more details, see Documentation of BufferCopy.BlockCopy

这篇关于将一维数组插入多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆