namespace ConsoleApp456
{
internal class Program
{
static void Main(string[] args)
{
int a = 4;
int[] b = new int[7] {0,1,2,3,7,8,9 };
int[] c = new int[3] {4,5,6 };
if (a > (b.Length + c.Length))
{
a= b.Length+c.Length-1;
}
int[] f = new int[b.Length+c.Length];
for (int i = 0; i < f.Length; i++)
{
if (a >= 0)
{
if (i < a)
{
f[i] = b[i];
}
else if (i == a)
{
for (int j = 0; j <c.Length; j++)
{
f[i+j] = c[j];
}
}
else if (i > a)
{
f[i] = b[i-3];
}
}
else
{
Console.WriteLine();
}
}
Console.WriteLine("原来的数组1是:");
foreach (int i in b)
{
Console.Write(i+" ");
}
Console.WriteLine();
Console.WriteLine("要添加的数组2是:");
Console.Write(" ");
foreach (int i in c)
{
Console.Write(i + " ");
}
Console.WriteLine() ;
Console.WriteLine("添加后的数组3是:");
foreach (int i in f)
{
Console.Write(i+" ");
}
Console.ReadLine();
}
}
}
原来的数组1是:
0 1 2 3 7 8 9
要添加的数组2是:
4 5 6
添加后的数组3是:
0 1 2 3 4 2 3 7 8 9