c# - Why the output textbox doesn't show the return value my function gives? -
i intend show results in textbox. code this:
private void run_click(object sender, eventargs e) { geneticalgorithm mygeneticalgorithm=new geneticalgorithm(); geneticalgorithm.gaoutput showresult = mygeneticalgorithm.ga(); string output; output = showresult; this.output.text = output; } class geneticalgorithm { public void reset() { messagebox.show("fine"); } public void initial() { messagebox.show("good"); } public class gaoutput { public string generation; } public gaoutput ga() { gaoutput onegeneration = new gaoutput(); onegeneration.generation = "bad"; homecoming onegeneration; } }
after running, gives me results as: windowsformsapplication1.geneticalgorithm+gaoutput
anyone can help me? give thanks much!
your showresult
variable not string, when assigned one, .net implicitly converted string. since there no tostring()
method, gave generic type definition string instead ("windowsformsapplication1.geneticalgorithm+gaoutput").
it looks want output generation
field, is string, change:
output = showresult;
to
output = showresult.generation;
and should start working.
also, if aren't planning on doing much else new generation
, shorten code, way downwards to:
this.output.text = (new geneticalgorithm()).ga().generation;
you might want think keeping local instance of geneticalgorithm
don't have maintain creating new instances.
c#
No comments:
Post a Comment