1
I’m trying to add the value of a result of mine while, and then carry it on my GridView. But I’m having a problem adding value to mine List<>. Does not accept adding prob1.vTotal in lstTotal.
namespace AvalicaoPratica.View
{
public partial class Home : System.Web.UI.Page
{
List<_Problema1> lstTotal = new List<_Problema1>();
protected void Page_Load(object sender, EventArgs e)
{
_Problema1 prob1 = new _Problema1();
while (prob1.Cont <= 64)
{
prob1.Vtotal = prob1.Vtotal + prob1.Graos;
prob1.Graos = prob1.Graos * 2;
prob1.Cont += 1;
}
lstTotal.Add(prob1.Vtotal);
GridView1.DataSource = lstTotal;
GridView1.DataBind();
}
}
}
My class
public class _Problema1
{
private int vtotal = 0;
public int Vtotal
{
get { return vtotal; }
set { vtotal = value; }
}
private int cont;
public int Cont
{
get { return cont; }
set { cont = value; }
}
private int graos = 1;
public int Graos
{
get { return graos; }
set { graos = value; }
}
}
Prefer to post code as text, it is easier for people to work with it. And what’s the problem? It does not accept add
prob1.vTotalinlstTotal?– Maniero
Yeah, that’s the problem.
– Vinícius
And what is the composition of
_Problema1?prob1.vTotalis a numerical type, aint,Decimalor something like that, right?– Maniero
_Problema1 is my class, where to define my 3 variables as int type.
– Vinícius
I know, but I’d need to know what her composition is to help you.
– Maniero
Okay, I posted my class code.
– Vinícius
Let’s go continue this discussão in chat.
– Vinícius