C
Charles
Hello all,
I'm trying to convert a Java Genetic Programming program to C#.
I don't know how to convert the following Java code:
Object choice = functionSet.getSelectedItem(choice)).value();
Class cls = ((ProgramChoice) choice;
function = (Function) cls.newInstance();
The object "choice" shows that a Subtraction class (i.e. "sub") was selected,
and therefore, "Function" should be set to the "Substraction" class.
"Function" is an abstract class, and the "Substraction" classs is:
internal class Subtraction : Function {
internal Subtraction() {
arg = new GeneticProgram[2];
}
override internal string Name {
get {
return "sub";
}
}
override internal double eval(double x) {
return arg[0].eval(x) - arg[1].eval(x);
}
}
Here is ProgramChoice:
class ProgramChoice {
private object cls;
private string text;
public ProgramChoice(string text_, object cls_) {
cls = cls_;
text = text_;
}
public override string ToString() {
return text;
}
public object Value {
get {
return cls;
}
}
}
Any help will be greatly appreciated.
Charles
I'm trying to convert a Java Genetic Programming program to C#.
I don't know how to convert the following Java code:
Object choice = functionSet.getSelectedItem(choice)).value();
Class cls = ((ProgramChoice) choice;
function = (Function) cls.newInstance();
The object "choice" shows that a Subtraction class (i.e. "sub") was selected,
and therefore, "Function" should be set to the "Substraction" class.
"Function" is an abstract class, and the "Substraction" classs is:
internal class Subtraction : Function {
internal Subtraction() {
arg = new GeneticProgram[2];
}
override internal string Name {
get {
return "sub";
}
}
override internal double eval(double x) {
return arg[0].eval(x) - arg[1].eval(x);
}
}
Here is ProgramChoice:
class ProgramChoice {
private object cls;
private string text;
public ProgramChoice(string text_, object cls_) {
cls = cls_;
text = text_;
}
public override string ToString() {
return text;
}
public object Value {
get {
return cls;
}
}
}
Any help will be greatly appreciated.
Charles