How to create an array with the same size as another array without copying it?

0
    private void InversaoString(string Texto, int Tamanho)
    {
        char[] arrChar = Texto.ToCharArray();
        char arrChar2;
        int indice = 0;
        for(Tamanho = arrChar.Length-1; Tamanho>=0; Tamanho--)
        {
            arrChar2(indice) = arrChar;
            indice++;
        }
        string Novo = new string(arrChar2);
        txtSaida.Text = Novo;

    }

See that I copy the string Texto to an array. Right now I create another array, but it has a but I want arrChar2 to have the same size as arrChar , I tried to use the Length method but without success. How should I proceed? (I want to do this because I want to invert the Text string).

    
asked by anonymous 17.02.2018 / 19:08

1 answer

0

With Length working normally, look at an example:

private string InversaoString(string Texto)
{
    char[] arrChar = Texto.ToCharArray();
    char[] arrChar2 = new char[arrChar.Length];

    for (int i = arrChar.Length - 1, i1 = 0; i >= 0; i--, i1++)
        arrChar2[i1] = arrChar[i];

    return new string(arrChar2);
}

To call the function do this:

Console.WriteLine(InversaoString("Teste"));
    
17.02.2018 / 19:35