Nested instances in C#

Posted by user32848 on Stack Overflow See other posts from Stack Overflow or by user32848
Published on 2011-01-18T01:48:49Z Indexed on 2011/01/18 1:53 UTC
Read the original article Hit count: 507

Filed under:
 I'm trying to translate some C++ code for a neural net into C#.  I first took the C++ code, from a 1993 book, and ran it.  Then translated it using the STL and it ran again.  Now I'm trying to get it into C# with Visual Web Developer 2008 Express.
 The original code used "friend" classes and I'm just trying to do the same making everything "public".

 The following code compiles but only gives null references when run:

public class ineuron
{
     public Double weight, activation;

     public ineuron(Double set_wt)
     {
         weight = set_wt;
     }

...

 public class netwrk
 {
     public oneuron onrn;
     public ineuron in1, in2, in3, in4;

     public netwrk( Double inp_1, Double inp_2, Double inp_3, Double inp_4 )
     {
         ineuron in1 = new ineuron(inp_1);
         ineuron in2 = new ineuron(inp_2);

...

and later, in some code called by a button push:

netwrk ntw = new netwrk(i_n1, i_n2, i_n3, i_n4);

Unfortunately, trying to use: ntw.in1.activation

etc. leads to null reference runtime errors.

What am I forgetting to do?

 Barney

© Stack Overflow or respective owner

Related posts about c#