开发者

How to create a new array in while loop with each iteration?

I've got 开发者_Python百科a while loop that's doing some stuff, and what I want is for it to create a new array each time.

while(condition){
//do some stuff
//create an array x[]
//amend values in array
//save as new array each time until loop finished
}

Actually i need to store the comma separated values of different datatypes in an array using split.And then i hav to sort these values comparing zeroth position element of all rows.


Declare and create an "array of arrays" before the loop, and add each new array to it.


It sounds like you need some specific help. If you don't know how many arrays you'll create I suggest a List<[element type]>...

List<List<int>> outerList = new List<List<int>>();
while(condition)
{
   List<int> loopList = new List<int>();

   loopList.Add(5);
   loopList.Add(1);
   loopList.Add(27);

   outerList.Add(loopList);
}


Use a List, as you can just do something simple like this:

List<string[]> myArrayList = new List<string[]>();
while(condition)
{
    string[] blah = new string[10];
    blah[0] = "whatever";
    myArrayList.Add(blah);
}

Edit: to read stuff back out of the List<> of arrays, just do a foreach:

foreach (string[] myArray in myArrayList)
{
    //each instance of 'myArray' is one of the arrays you added previously

    for (int ii = 0; ii < myArray.Length; ii++)
    {
        string myString = myArray[ii];

        //do stuff with my array entry
    }
}


double[] x = new double[5] { 20, 15, 25, 10, 5 };
Array.Sort(x);

double vaule = 0;
double y = 0;

while (y < 5)
{
    if (vaule < x[(int)y++]);
    {
        vaule = x[(int)y++];
    }
    y++;
}

double[] myarray = Convert.ToString(x[5]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜