关于C#交错数组动态自动递增数组未正确打印值

关于C#交错数组动态自动递增数组未正确打印值,c#,arrays,dynamic,jagged-arrays,C#,Arrays,Dynamic,Jagged Arrays,我正在使用自动增量阵列,但对于锯齿阵列,此逻辑无法正常工作: namespace TESETER { class Program { static void Main(string[] args) { int q, moj = 0; int[][] arr = new int[1][]; int[][] b; b = arr; a

我正在使用自动增量阵列,但对于锯齿阵列,此逻辑无法正常工作:

namespace TESETER
{
    class Program
    {
        static void Main(string[] args)
        {
            int q, moj = 0;
            int[][] arr = new int[1][];
            int[][] b;
            b = arr;
            arr[0] = new int[1];
            b[0] = arr[0];
            while (moj < 3)
            {
                Console.WriteLine("interger");
                int.TryParse(Console.ReadLine(), out q);
                if (moj < 1)
                { arr[0][0] = q; moj++; }
                else
                {
                    moj++; arr[0] = new int[moj];
                    for (int i = 0; i < moj - 1; i++)
                    {
                        arr[0][i] = b[0][i];
                    }
                    arr[0][moj - 1] = q;
                    b = arr;
                    b[0] = arr[0];
                }
            }
            Console.WriteLine(arr[0][0]);
            Console.WriteLine(arr[0][1]);
            Console.WriteLine(arr[0][2]);
            Console.ReadLine();
        }
    }
}
名称空间测试仪
{
班级计划
{
静态void Main(字符串[]参数)
{
int q,moj=0;
int[]arr=新int[1][];
int[]b;
b=arr;
arr[0]=新整数[1];
b[0]=arr[0];
而(moj<3)
{
控制台。WriteLine(“集成”);
int.TryParse(Console.ReadLine(),out q);
if(moj<1)
{arr[0][0]=q;moj++;}
其他的
{
moj++;arr[0]=新整数[moj];
对于(int i=0;i
输出:整数7整数8整数9 009


如果输入为789,请帮助我输出789。我建议使用
列表
而不是锯齿数组。当您向其添加新元素时,它会自动调整大小

如果必须在此处使用锯齿数组,请不要使用赋值来保留以前的值。使用
数组。改为复制

using System;
namespace TESETER
{
    class Program
    {
        static void Main(string[] args)
    {
        int q, moj = 0;
        int[][] arr = new int[1][];
        int[][] b = new int[1][];
        // b = arr;
        // arr[0] = new int[1];
        // Array.Copy(arr[0], b[0]);
        while (moj < 3)
        {
            Console.WriteLine("interger");
            int.TryParse(Console.ReadLine(), out q);
            if (moj < 1)
            { arr[0][0] = q; moj++; }
            else
            {
                moj++; arr[0] = new int[moj];
                for (int i = 0; i < moj - 1; i++)
                {
                    arr[0][i] = b[0][i];
                }
                arr[0][moj - 1] = q;
                Array.Copy(arr, b);
                //b[0] = arr[0];
            }
        }
        Console.WriteLine(arr[0][0]);
        Console.WriteLine(arr[0][1]);
        Console.WriteLine(arr[0][2]);
        Console.ReadLine();
    }
}
}
使用系统;
名称空间测试仪
{
班级计划
{
静态void Main(字符串[]参数)
{
int q,moj=0;
int[]arr=新int[1][];
int[]b=新的int[1][];
//b=arr;
//arr[0]=新整数[1];
//Copy(arr[0],b[0]);
而(moj<3)
{
控制台。WriteLine(“集成”);
int.TryParse(Console.ReadLine(),out q);
if(moj<1)
{arr[0][0]=q;moj++;}
其他的
{
moj++;arr[0]=新整数[moj];
对于(int i=0;i
你能详细说明一下你想在算法中实现什么吗?嘿,我想对上面的锯齿阵列代码进行运行时增量,将其限制为三个,但如果我在运行时更改(mojare,你用的是“b”要保留以前的值吗?目前它引用的是同一个对象。数组的单个整数数组很多。你节省了很多时间。谢谢!这就是我想要的,现在它工作得很好。对不起,英语不好