开发者

Trying to put a unique number code in all of my arrays

Say I have 3 arrays of arrays and when I write in any of them my counter goes up by one every insertion I do.How can I show on screen the data I inserted the same order I inserted them with that unique code it was printed when I was inserting them?

array ar1=new array[3];

array2 ar2=new array2[3];

array3 ar3=new array3[3];

I'm working on C# with 6 files. My main calls methods from the other 3 files. My base abstract class calls a counter (named code) from a constructor, which is being inserted on every array.My main is without Heredity, but calls the variables from the 3 files that are connected with heredity to the abstract base class.

This is my main and how I fill my first array.Same with different variables on the other two arrays.

i ++; ar1[i] = new array();

{

 Console.WriteLine("Inserting on first array");
 Console.WriteLine("\n\nCode :{0}",code);

 ar1[i].Inserting_data();  // this is the method where I fill my arrays

}

And this is how I try to call my previous insertions using a method a开发者_如何学JAVAgain.

for (int x = 0; x <= i; x++) {

    Console.WriteLine("code :{0}",code); //trying to print the unique code but it prints total.
    ar1[x].Print_data(); //the method for printing my insertions

}

If I leave the program like this when I insert data(up to 3 on every array) My counter is working fine and when I print them on screen, it prints them on the correct order but in the Console.WriteLine that there should be the unique code I want for every insertion (from 1 to 9 on that example, if I fill them all),my counter shows me the total insertions I have.

If I try rather than printing my counter, printing each variable from the For command,I get numbers from 0 to 2 max since that's what I put on my For. I can't unite my 3 arrays since each of them holds different variables and is on 3 different files.

Hope that helped.


I found the problem at last.. I had to add another variable on the base abstract class.Inside the constructor I had to write that the new variable (say s)was (s=+1+count++) and add it with a property(set,get) on my main.It worked fine.

Thanks for the time it took you to see this topic and ask some questions to help me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜