Search code examples
c#arraysstringjoin

C# Putting an Array in to a String Backward


I have an Array which I filled up. Now the problem I have is I want to put the array together in to one string but starting from the end of the Array.

while(Opsplitser > -1)
{
    EindResultaat = EindResultaat + string.Join(" ",  Opsplitsen[Opsplitser]);
    Opsplitser--;

}

I have used as code but the problem I have is that the join puts the whole array eventually in one big string but doesn't put a Whitespace in between the text of the arrays. is there a different way I can use to put the array in to one string with the spaces in between?


Solution

  • Use this code:

    string str = string.Join(" ", Opsplitsen.Reverse());
    

    The Linq operation Reverse() inverts the direction of the items in the array and Join with a whitespace as first parameter joins the items with a whitespace between all items.