c# - Passing value to another class -


hi learn how pass values. have 2 sets of arrays: moment array , curvature array. each array read textfile clicking button in mainwindow class shown below.

public partial class mainwindow : window {     public mainwindow()     {         initializecomponent();     }      private void button_click(object sender, routedeventargs e)     {         input ip = new input();          double[] curvature = new double[40];         double[] moment = new double[40];          string path;         path = "c:\\desktop\\48co.out";         string[] records = file.readalllines(path);         int linenumber = 0;         string[][] rows = new string[40][];          (int = 0; < records.length; i++)         {             if (records[i] == "step epscmax   in.    tens.  comp.  comp. tens.   force   force  rad/in  (k-ft)")             {                  linenumber = + 1;              }         }          (int = linenumber; < linenumber + 40; i++)         {             rows[i - linenumber] = records[i].split(new[] { " " }, stringsplitoptions.removeemptyentries);         }          (int = 0; < 40; i++)         {             curvature[i] = double.parse(rows[i][9]);             moment[i] = double.parse(rows[i][10]);         }          ip.curvature = curvature;         ip.moment = moment;          plotmphi plotmphi = new plotmphi();         plotmphi.show();     } } 

and these 2 arrays passed class called "input".

class input {     public input()     {         double[] curvature = new double[40];         double[] moment = new double[40];     }      public double[] curvature { get; set; }     public double[] moment { get; set; } } 

my idea store input parameters in input class , if methods in other classes need them, can passed to. in case, wanted plot chart x points curvature array , y points moment array using oxyplot in wpf called plotmphi.

public partial class plotmphi : window {     public plotmphi()     {         var vm = new mvmmphi();         this.datacontext = vm;         initializecomponent();     }  }  class mvmmphi {     public collection<meamphi> meamphis { get; private set; }      public mvmmphi()     {         meamphis = new collection<meamphi>();         input ip = new input();          (int = 0; < 40; i++)         {             meamphis.add(new meamphi { curvature = ip.curvature[i],moment = ip.moment[i]});         }     } }  public class meamphi {     public double curvature { get; set; }     public double moment { get; set; } } 

here xaml file plotting chart.

<window x:class="xsectionwin.plotmphi"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"      xmlns:oxy="clr-namespace:oxyplot.wpf;assembly=oxyplot.wpf"      title="moment-curvature" height="480" width="640">      <grid>         <grid.rowdefinitions>             <rowdefinition height="auto"/>             <rowdefinition height="*"/>         </grid.rowdefinitions>         <menu dockpanel.dock="top">             <menuitem header="_file">                 <menuitem header="save plot..." click="saveplot_click"/>                 <separator />                 <menuitem header="_exit" click="exit_click" />             </menuitem>         </menu>         <oxy:plot grid.row="1" x:name="plot" title="moment-curvature" subtitle="{binding subtitle}" >             <oxy:plot.axes>                 <oxy:linearaxis position="bottom" title="curvature (rad/in)" titlefont="arial" titlefontsize="12" titlecolor="black"/>                 <oxy:linearaxis position="left" title="momennt (kips-in)" titlefont="arial" titlefontsize="12" titlecolor="black"/>             </oxy:plot.axes>             <oxy:plot.series>                 <oxy:lineseries title="m-curvature" datafieldx="period_t" datafieldy="acc_t" color="red"  strokethickness="3" itemssource="{binding meamphis}"/>              </oxy:plot.series>         </oxy:plot>     </grid> </window> 

the problem these 2 arrays not passed mvmmphi class. checked procedure step step clicking f11 key. seems these arrays passed input class until reaching

plotmphi plotmphi = new plotmphi(); plotmphi.show(); 

once step, moments , curvature arrays in inout become null. encountered before did put these arrays in method directly i.e.

plotmphi plotmphi = new plotmphi(moment,curvature); 

this has worked me until now. need handle lot of arrays later looking easy way handle , know why idea not work. new in programming world. don't want spoon-fed suggestions or tips appreciated. if need additional info, please let me know. time , help,

the constructor datacontext class made take parameter of type input change code thus

public mvmmphi(input data) {     meamphis = new collection<meamphi>();      (int = 0; < 40; i++)     {              meamphis.add(new meamphi                                  {                                      curvature = data.curvature[i],                                      moment = data.moment[i]                                  });      } } 

this may not solve problems might make thinks little more direct.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -