Most of my studying of the c# was with the earlier releases I am not very familiar with this kind of code. I was provided with this snipped bellow but I am having a hard time to add the products dynamically to the items property of the anonymous object.
var body = new
{
items = new[] {
new {
name = "Product 1",
value = 1000,
amount = 2
}
},
shippings = new[] {
new {
name = "Default Shipping Cost",
value = 100
}
}
};
The idea would be:
var body = new { items = new[]{ new { } } };
foreach(Modelos.Produto p in carrinho.Items)
{
body.items // add elements { name = p.name }
}
new { items = new[]{ new { } } };supposed to produce? An anonymous object that has an array of anonymous objects? I don't see the point of such illegibility, I'd keep it to using classes for something like this