C# convert Object to Object[]

Asked

Viewed 44 times

1

I have the following code:

var pagamento = new PefService.Pagamento();
pagamento.IdPagamentoCliente = "teste";

......

//resquest.Pagamentos é PefService.Pagamento[]
request.Pagamentos = pagamento; //error

I’m making the following mistake

Connot implicitly Convert type 'Payment' to 'Payment[]'

  • 1

    Your question brings a doubt as to what it is request and what has in Pagamentos, no use passing only the type, need to show if you have instance and positions in array

  • request. Payments is a list ? Shows the rest of the code.

1 answer

4


One way you do it is this:

var pagamentos = new List<PerfService.Pagamento>(); 
pagamentos.Add(new PerfService.Pagamento() {
    IdPagamentoCliente = "Teste",
});

request.Pagamentos = pagamentos.ToArray();

Each payment you can add to this list.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.