working with user created classes

  • Thread starter Thread starter Serdar C
  • Start date Start date
S

Serdar C

hi everyone.. i have a problem that i couldnt find the answer through the
web..
maybe i am asking the wrong question.. but here comes my problem..

----------------------------------

using System;

namespace NeuralNetwork

{

public class SCNeuralNetwork

{

private double activation;

private double treshold;

public SCNeuralNetwork()

{

Random random = new Random();

activation = random.NextDouble();

treshold = random.NextDouble();

}

public SCNeuralNetwork(double act,double tre)

{

this.Activation = act;

this.Treshold = tre;

}

public double Activation

{

set{activation = value;}

get{return activation;}

}

public double Treshold

{

set{treshold = value;}

get{return treshold;}

}


}

}





everything works good but when i try the call my class from main program
like this:



mainprogram.SCNeuralnetwork []network = new mainprogram.SCNeuralnetwork[10];

network[0].Activation = 10;



when i try to do something like this program throws "Object reference not
set to an instance of an object." exception.

what am i doing wrong? i cant set or read the values from the aray of
classes..

p.s: it works fine when i create the classs like ;



mainprogram.SCNeuralnetwork network = new mainprogram.SCNeuralnetwork();



thanks for helping and spending your time.. have a nice day..
 
When you create an array, you are basically only creating an array that will
hold x items. Each item is not created for you...you have to do that
explicitly.

try:
mainprogram.SCNeuralnetwork[] network = new mainprogram.SCNeuralnetwork[10];
for (int i = 0; i < network.Length; i++)
{
network = new SCNeuralnetwork();
}

-sb
 
ah.. thank you for helping!.. its working now :)


SB said:
When you create an array, you are basically only creating an array that will
hold x items. Each item is not created for you...you have to do that
explicitly.

try:
mainprogram.SCNeuralnetwork[] network = new mainprogram.SCNeuralnetwork[10];
for (int i = 0; i < network.Length; i++)
{
network = new SCNeuralnetwork();
}

-sb

Serdar C said:
hi everyone.. i have a problem that i couldnt find the answer through the
web..
maybe i am asking the wrong question.. but here comes my problem..

----------------------------------

using System;

namespace NeuralNetwork

{

public class SCNeuralNetwork

{

private double activation;

private double treshold;

public SCNeuralNetwork()

{

Random random = new Random();

activation = random.NextDouble();

treshold = random.NextDouble();

}

public SCNeuralNetwork(double act,double tre)

{

this.Activation = act;

this.Treshold = tre;

}

public double Activation

{

set{activation = value;}

get{return activation;}

}

public double Treshold

{

set{treshold = value;}

get{return treshold;}

}


}

}





everything works good but when i try the call my class from main program
like this:



mainprogram.SCNeuralnetwork []network = new
mainprogram.SCNeuralnetwork[10];

network[0].Activation = 10;



when i try to do something like this program throws "Object reference not
set to an instance of an object." exception.

what am i doing wrong? i cant set or read the values from the aray of
classes..

p.s: it works fine when i create the classs like ;



mainprogram.SCNeuralnetwork network = new mainprogram.SCNeuralnetwork();



thanks for helping and spending your time.. have a nice day..
 
Back
Top