4
How can I select an item from a list by the index, this being equal to the iteration value of a for
?
I tried to accomplish using LINQ, while compiling and inspecting the StringBuilder
which would store the item, I get only the name of the using
concatenated with the project name and the class.
StringBuilder dados = new StringBuilder(); //Cria StringBuilder
int Contador = (from q in Lista select q.Codigo).Count();
....
///método que gera string
...
for (int i = quantidade * 10; i < (quantidade * 10) + 10; i++)
{
if (i >= Contador)
{
break;
}
var cod = Lista.Where(c => c.Codigo == i.ToString()).Select(c=>c.Codigo);
dados.AppendLine(Convert.ToString(cod));
}
Result of inspection of StringBuilder
:
System.Linq.Enumerable+Whereselectlistiterator`2[projectinho. Pedido+Item,System.String]
Why does this happen? How to solve?
Missing chunks of code, for example where the variable is
Contador
. It would be nice to know also how this list is, although you can already see at least one error. What do you call storing the item? The question is not clear exactly as the string should be mounted.– Maniero
Hello Maniero, The Counter variable receives the amount of items in the List. This is a list of an object. Storing the item would be to take the Product Code, stored in the variable
cod
and add toStringBuilder
– Noob