behi behi behi behi - 1 month ago 13
C# Question

Why i can not save list in c# list?

I'm new in

c#
and write this class:


public class MANAGER
{
public string VersionName { get; set; }
public Double Value { get; set; }

}




and use this:


List<MANAGER> lstSummary = new List<MANAGER>();
MANAGER summary = new MANAGER();
summary.VersionName = "12";
summary.Value =12;
lstSummary.Add(summary);
summary.VersionName = "13";
summary.Value = 19;
lstSummary.Add(summary);




but up code just save latest class record ,means just save
VersionName=13 and Value=19
,How can i solve that problem?thanks.

Ted Ted
Answer

You have to re-instantiate the summary variable like so:

MANAGER summary = new MANAGER();
summary.VersionName = "12";
summary.Value =12;
lstSummary.Add(summary);

summary = new MANAGER(); // <-- add this
summary.VersionName = "13";
summary.Value = 19;
lstSummary.Add(summary);