日期:2014-05-18  浏览次数:21195 次

一维数组偏移取值
定义数组double[] arr ={ 10, 11, 12, 10, 15, 14, 11, 16 };
如何能每次取值的时候进行偏移?0-5,1-6,2-7....
如果看不懂我把想要的结果列举出来
在循环之后
第一次循环结束double[] arr1={10,11,12,10,15,14};
第二次循环结束double[] arr1={11,12,10,15,14,11};
第三次循环结束double[] arr1={12,10,15,14,11,16};
.....

清高手帮忙解决一下...



------解决方案--------------------
Array.Copy 方法 (Array, Int32, Array, Int32, Int32) 
  
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 

http://feiyun0112.cnblogs.com/
------解决方案--------------------

private static double[] GetArray(double[] p_List, int p_StarIndex, int p_EndIndex)
{
int _Count = p_EndIndex - p_StarIndex;

double[] _Return = new double[_Count];
for (int i = 0; i != _Count; i++)
{
_Return[i] = p_List[p_StarIndex + i];
}
return _Return;
}
private void button1_Click(object sender, EventArgs e)
{

double[] arr ={ 10, 11, 12, 10, 15, 14, 11, 16 };

for (int i = 0; i != 3; i++)
{
double[] _OneList = GetArray(arr, i, i+6);
}
}
------解决方案--------------------
探讨
Array.Copy 方法 (Array, Int32, Array, Int32, Int32)

*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)

http://feiyun0112.cnblogs.com/

------解决方案--------------------
C# code
class test
{
    static void Main()
    {
        double[] arr ={ 10, 11, 12, 10, 15, 14, 11, 16}; 
        double[] arr2=new double[6];
        for(int i=0;i<3;i++)
        {
            Array.Copy(arr,i,arr2,0,6);        
            foreach(double j in arr2)
            {
            Console.Write(j.ToString()+" ");
            }
            Console.WriteLine();
        }
    }    
}

------解决方案--------------------
每次循环取值的时候,让第一个元素的下标+1就行了吧,取的长度都是6
------解决方案--------------------
C# code

int count = 6;
int start = 0;
double[] arr ={ 10, 11, 12, 10, 15, 14, 11, 16 }; 
double[] result = new double[count];
Array.Copy (arr, start, result, 0, count);

------解决方案--------------------
来晚了,上面有答案.
------解决方案--------------------
C# code

            double[] arr = { 10, 11, 12, 10, 15, 14, 11, 16 };
            List<double[]> list = new List<double[]>();
            for (int i = 0; i < arr.Length - 4; i++)
            {
                double[] arrTemp = new double[5];
                Array.Copy(arr, i, arrTemp, 0, 5);
                list.Add(arrTemp);
            }

------解决方案--------------------
两个循环。赋值的时候自加就可以了,想好逻辑很简单的~~~代码上面的基本都能用哦。。