.net - List of elements doesnt follow my recursion method c# -
i've got method calls (recursion). collects data need analyse. collects data in dto. dto setup:
public class sequencedto { public string sequence { get; set; } public list<element> statelist { get; set; } public sequencedto() { } public sequencedto(string sequence, list<element> statelist) { this.sequence = sequence; this.statelist = statelist; } }
this how initialize recursion method:
string seq = ""; list<element> elmlist = new list<element>(); initialseqdto.sequence = seq; initialseqdto.statelist = elmlist; analyze(element, initialseqdto); //the recursion method
the recursion method:
public void handleeventanalysis3(element elm, sequencedto dto) { sequencedto newseqdto = new sequencedto(); list<element> elmlist = new list<element>(); elmlist = dto.statelist; newseqdto.sequence = dto.sequence; newseqdto.statelist = elmlist; newseqdto.statelist.add(clientelement); if (!clientelement.name.equals("initial")) handleeventanalysis3(clientelement, newseqdto); if (clientelement.name.equals("initial")) { sequencelist.add(newseqdto); } }
this adding sequencedto's sequencelist. dto.statelist same every sequencedto. how can be?
you create new list<element>
:
list<element> elmlist = new list<element>();
but override reference old list:
elmlist = dto.statelist;
instead, can call tolist()
generate new list:
newseqdto.statelist = dto.statelist.tolist();
Comments
Post a Comment