Hello.
I'm trying to figure out the best way of communication between two classes:
(1) Now I have ServiceChild.My Method() which gets around 10 arguments using REF keyword in order to use arrays and variables and returns via those arguments the result values.
And I have more than one method of this type.
I don't like this kind of programming and I'm trying to make the code look more clear and short.
Yesterday I've tryed next scheme:
ServiceChild inherits MainForm to gain access to all necessary feilds and members, instead of getting them as method arguments.
The problem pops out on the run time - possible infinite recursion.
The cause: it's not allowed to make copy of child(inheritin g) class inside inherited class...
Here's the code:
Is there another "smart" way of handling this (1) ?
I'm trying to figure out the best way of communication between two classes:
- MainForm.cs
- ServiceChild.cs
(1) Now I have ServiceChild.My Method() which gets around 10 arguments using REF keyword in order to use arrays and variables and returns via those arguments the result values.
And I have more than one method of this type.
I don't like this kind of programming and I'm trying to make the code look more clear and short.
Yesterday I've tryed next scheme:
ServiceChild inherits MainForm to gain access to all necessary feilds and members, instead of getting them as method arguments.
The problem pops out on the run time - possible infinite recursion.
The cause: it's not allowed to make copy of child(inheritin g) class inside inherited class...
Here's the code:
Code:
public class Child : Form1 { public Child() { } public void MyMethod() { } public void printarr() { } } /////////////////////////////// public partial class Form1 : Form { public Form1() { InitializeComponent(); } private Child ch = new Child(); // runtime error - possible infinite recursion protected int[] array1 = new int[] {0, 1, 2, 3}; // inherited member private void button2_Click(object sender, EventArgs e) { ch.printarr(); } private void button1_Click(object sender, EventArgs e) { ch.MyMethod(); } }
Comment