0
I am trying to get the items from a generic list that I pass for reference to a class, but I only have as return the name of my project concatenated with the class. Below is a code fragment demonstrating how I am creating and passing the list by reference.
readonly Class.Orders order = new Class.Orders();
readonly Class.Items items = new Class.Items();
Class ItemsList
{
public int ID {get; set;}
public int Quantidade{get; set;}
}
List<Items> list = new List<Items>();
.
.
.
public void AdicionaItens() //Se produto já existe na lista, apenas somo a quantidade
{
int index = list.FindIndex(x=> x.ID == items.prod.ID);
if(index == -1)
{
list.Add (Items {ID = items.prod.ID, Quantidade= items.prod.Quantidade});
}
else
{
list[index].Quantidade += qtd;
}
}
public void EnviaLista()
{
orders.Imprimir(ref list);
}
Below is the Class I wish to pass the list by reference
StringBuilder sbString = new StringBuilder();
public void Imprimir(ref List<T>ListaSeparado)
{
foreach(var i in ListaSeparado)
{
sbString.AppendLine(i)
}
}
However when viewing the data added to StringBuilder
i have as a result my project name + class name (ProjectTest.ClassTest.ItemList
).
What should I do to properly access the list items?
Exactly what you wanted to appear?
– Ronaldo Araújo Alves
I was trying to get the ID and Quantity of the items in the Print List method...
– Leonardo
I understood. Another question: this
ItemsList
would be the same as theItems
?– Ronaldo Araújo Alves
No, actually the class
items
has some queries and validations of the Items... Already the ClassItemsList
would be a local class, just so I can create the list with the results ofItems
... I don’t know if it’s clear...– Leonardo