Как объединить несколько массивов в один массив в C #?
using System;
using System.Linq;
namespace Exp2
{
class Program2
{
static void Main(string[] args)
{
Program2 pgm = new Program2();
Console.Write("Enter number of Arrays do you want : ");
int numberOfArrays = int.Parse(Console.ReadLine());
int[] narray = new int[numberOfArrays];
int[] el=new int[100];
int[] el1 = new int[100];
for (int i = 0; i < narray.Length; i++)
{
Console.Write("Enter number of Elements do you want in Array {0}: ",i+1);
int ai = int.Parse(Console.ReadLine());
for (int j = 0; j < ai; j++)
{
Console.Write("Enter the {1} Elements do you want in Array {0}: ", i+1,j+1);
el[j]= int.Parse(Console.ReadLine());
}
el1 =el1.Concat(el).ToArray();
}
foreach (int val in el1)
{
Console.Write(val+" ");
}
Console.ReadLine();
}
}
}
Ввод:
Enter number of Arrays do you want : 3
Enter number of Elements do you want in Array 1: 3
Enter the 1 Elements do you want in Array 1: 5
Enter the 2 Elements do you want in Array 1: 6
Enter the 3 Elements do you want in Array 1: 9
Enter number of Elements do you want in Array 2: 4
Enter the 1 Elements do you want in Array 2: 5
Enter the 2 Elements do you want in Array 2: 8
Enter the 3 Elements do you want in Array 2: 2
Enter the 4 Elements do you want in Array 2: 2
Enter number of Elements do you want in Array 3: 5
Enter the 1 Elements do you want in Array 3: 32
Enter the 2 Elements do you want in Array 3: 4
Enter the 3 Elements do you want in Array 3: 6
Enter the 4 Elements do you want in Array 3: 6
Enter the 5 Elements do you want in Array 3: 4
Вывод:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 6 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 8 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 4 6 6 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Как можноЯ отображаю только ввод пользователя?