Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
反向数组的C#循环,该数组包含来自dataseries(提要)的最近7个数据_C#_Arrays_Loops_For Loop - Fatal编程技术网

反向数组的C#循环,该数组包含来自dataseries(提要)的最近7个数据

反向数组的C#循环,该数组包含来自dataseries(提要)的最近7个数据,c#,arrays,loops,for-loop,C#,Arrays,Loops,For Loop,首先,大家好,谢谢你们的帮助。这是我的第一个帖子/问题。我会尽量直截了当地说 public override void Calculate(int index) { for (int i = 0; i < 7; i++) { //.. if (a_gamma[index] == TAU[index]) { a_gamma_tau_health[i] = a_gamma[index];

首先,大家好,谢谢你们的帮助。这是我的第一个帖子/问题。我会尽量直截了当地说

public override void Calculate(int index)
{
    for (int i = 0; i < 7; i++)
    {
        //..
        if (a_gamma[index] == TAU[index])
        {
            a_gamma_tau_health[i] = a_gamma[index];
            TEST[index] = a_gamma[index];
        }
        //..
    }
}
公共覆盖无效计算(int索引)
{
对于(int i=0;i<7;i++)
{
//..
if(a_gamma[index]==TAU[index])
{
a_gamma_tau_health[i]=a_gamma[指数];
测试[指数]=a_伽马[指数];
}
//..
}
}
//输出

a_gamma_头_健康

|71.9 | 71.9 | 71.9 | 71.9 |

我需要修复这个for*循环,因为它将在所有7个索引中输出相同的值。并建议如何获取该数组的反向,该数组将包含来自DataSeries(feed)a_gamma的最新7个数据-该系列包含double.NaN或double值(我们需要查找)。因此需要阵列中的相关双重数据进行进一步评估

//信息

  • if条件用于查找_gamma中的双值 通过双空位;如果这是真的,我们有一个替身 发现我们需要在阵列内部

  • TAU和a_gamma不是静态数据序列,而是从右到左(例如[index-x])不断更新的新数据

  • 我能读取数据的唯一方法是槽[index],我已经在后台使用了它。我只需要一个循环来获取这些值并将它们写入数组

  • //更新

    我设法解决了这个问题,并显示了4个最新的数据,为进一步的操作做好了准备。这是我想要的循环的一个手动(如果)版本,我知道这是迄今为止最不优雅的拥有代码的方式,但至少现在你可以看到我需要什么。有人能给我一个更优雅的方法吗?我的目标是一个循环和数组,但任何更优雅的都可以。多谢各位

    public override void Calculate(int index)
        {
    
            //..
            int x = 0;
            int y = 0;
            int z = 0;
            var Display = 0.0;
            var Display2 = 0.0;
            var Display3 = 0.0;
            var Display4 = 0.0;
            for (int a = 0; a < 700; a++)
            {
                if (a_gamma[index - a] == TAU[index - a])
                {
                    if ((x == 0) && (y == 0) && (z == 0))
                    {
                        Display = a_gamma[index - a];
                        x++;
                    }
                    else
                    {
                        if ((x != 0) && (y == 0) && (z == 0))
                        {
                            Display2 = a_gamma[index - a];
                            y++;
                        }
                        else
                        {
                            if ((x != 0) && (y != 0) && (z == 0))
                            {
                                Display3 = a_gamma[index - a];
                                z++;
                            }
                            else
                            {
                                Display4 = a_gamma[index - a];
                                x = 0;
                                y = 0;
                                z = 0;
                            }
                        }
                    }
    
                }
            }
            //..
    
        }
    
    公共覆盖无效计算(int索引)
    {
    //..
    int x=0;
    int y=0;
    int z=0;
    var显示=0.0;
    var Display2=0.0;
    var Display3=0.0;
    var Display4=0.0;
    对于(int a=0;a<700;a++)
    {
    if(a_gamma[index-a]==TAU[index-a])
    {
    如果((x==0)和&(y==0)和&(z==0))
    {
    显示=a_伽马[索引-a];
    x++;
    }
    其他的
    {
    如果((x!=0)&&(y==0)&&(z==0))
    {
    显示2=a_伽马[索引-a];
    y++;
    }
    其他的
    {
    如果((x!=0)和&(y!=0)和&(z==0))
    {
    显示3=a_伽马[指数-a];
    z++;
    }
    其他的
    {
    显示4=a_伽马[指数-a];
    x=0;
    y=0;
    z=0;
    }
    }
    }
    }
    }
    //..
    }
    
    虽然在没有更多代码的情况下很难进行评估,但您似乎从未在循环中使用索引器(i),而是使用函数的参数(index)

    也许是这样的:

        public override void Calculate(int index)
        {
            for (int i = 0; i < 7; i++)
            {
                if (a_gamma[i] == TAU[index])
                {
                    a_gamma_tau_health[i] = a_gamma[i];
                    TEST[i] = a_gamma[i];
                }
            }
    
        }
    
    公共覆盖无效计算(int索引)
    {
    对于(int i=0;i<7;i++)
    {
    if(a_gamma[i]==TAU[index])
    {
    a_gamma_tau_health[i]=a_gamma[i];
    测试[i]=a_伽马[i];
    }
    }
    }
    
    是否应该使用中的
    i
    而不是
    index
    ,来查找for循环中数组的索引?修复什么?预期的行为是什么?在示例中,您在哪里有任何输出?此外,您只在一个位置使用迭代变量
    i
    :赋值,这意味着如果您的
    if
    计算结果为
    true
    ,它将覆盖数组
    a_gamma\u tau\u health
    中的所有值,请写清楚的问题,并避免像str8forward那样写得不好。使用这样的作品显然缺乏努力,在专业网站上是不可接受的。这显然是一个错误,但出于良好的意图。我想在写作中有点个性吧。无论如何,谢谢你关注这个令人惊叹的网站。我不知道会发生什么。这显然是尖锐和专业的。@unhylysheep-你在做什么。也许这就是为什么我在所有7中得到相同的值。我该如何解决或修复这个问题?如果我的循环将数据系列7的值推过并找到它需要的值,那么它应该会起作用。但是[index]会处理这个问题,我需要[I]在(if)为真时输入它将找到的值。我只需要最后7个值。测试[索引]在所有数据正确的情况下亮起,但a_gamma_tau_health的最后一个值重复了7次。