Arrays

How do i print the elements of a one dimensional arrray in reverse order.

Comments

  • Hi,

    for example you can use a dummy register where to
    put data inverted using a "for cycle" in which you decrement
    your index, and then you can print the dummy register instead
    of the original one.

    Bye
  • Thannx dude but my problem is that i am new to C# and i just need code that could help me achieve the task,
  • An array in C# is simply a collection of objects in sequential order. Each item in the array can be referenced by an integer index. Array indices start at zero and go to the length of the array -1. To output each array element, a for or while loop can be used.

    Therefore to print an array in order:
    [code]
    string[] ar = new string[] {"one", "two", "three"};
    for(int i=0; i -1; i--)
    {
    Console.WriteLine(ar[i]);
    }
    [/code]
    OR
    [code]
    string[] ar = new string[] {"one", "two", "three"};
    int i = ar.Length - 1;
    while(i > -1)
    {
    Console.WriteLine(ar[i]);
    i--;
    }
    [/code]
  • Thanxs alot asponge.
  • Thank you for your valuable response. It worked for me
    [url=http://www.marka-turk.com]Marka Tescili[/url]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories