I have a static dictionary that i create globally. I declare it like this =>
static Dictionary<int, Artikels> dicArtikels = new Dictionary<int, Artikels>();
Artikels is a class i have created to store the products.
for (int rijenTeller = 0; rijenTeller < aantalRijen; rijenTeller++)
{
Artikels artikel = new Artikels();
if (dicArtikels.ContainsKey(rijenTeller))
{
artikel = dicArtikels[rijenTeller];
}
else
{
dicArtikels.Add(rijenTeller, artikel);
}
artikel.naam = txtNameInstance.Text;
artikel.prijs = txtPriceInstance.Text;
dicArtikels[rijenTeller] = artikel;
artikel = null;
}
Well when i print the output with a button like below it's always showing the value of the last instance. That't not what i want. I want the value of the seperate instances but they are always getting the same value. =>
protected void Button3_Click(object sender, EventArgs e)
{
try
{
Artikels artikel = new Artikels();
artikel = dicArtikels[0];
Response.Write(artikel.naam.ToString() + " -- " + artikel.prijsExclBTW.ToString());
artikel = dicArtikels[3];
Response.Write(artikel.naam.ToString() + " -- " + artikel.prijsExclBTW.ToString());
artikel = dicArtikels[1];
Response.Write(artikel.naam.ToString() + " -- " + artikel.prijsExclBTW.ToString());
artikel = dicArtikels[2];
Response.Write(artikel.naam.ToString() + " -- " + artikel.prijsExclBTW.ToString());
}
catch (Exception ex)
{
Response.Write("Foutbericht Artikelchangedssssssss: " + ex.Message);
}
}