Click here to Skip to main content
15,908,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
i have 2 forms ,form1 has classe inside class ,i generate public static array of those classes in form1.
static public father[] xx = new father[3];//<----see line A in the code below
In form2 i wrote
int saveIn;
saveIn = Form1.xx[0].P[0].V[0].X;
the progrm did not run the error is
Inconsistent accessibility: field type 'test.Form1.father[]' is less accessible than field 'test.Form1.xx'

how could i redefine the above classes in order to have the program run ?
many thanks

What I have tried:

//Classes are in form1
    class MyNum
    {
        private int x;
        public MyNum() { }
        public MyNum(int Xx) { X = Xx; }
        public int X { get { return x; } set { x = value; } }
    }//MyNum
    class Sun
    {
        public int n;
        public MyNum[] V;
        public Sun() { }
        public Sun(int Xn) { N = Xn; }
        public int N { get { return n; } set { n = value; } }
        public MyNum this[int i]
        { get { return V[i]; } set { V[i] = value; } }
    }//MyLine
    class father
    {
        public int x;
        public Sun[] P;
        public father() { }
        public father(int Xx) { X = Xx; }
        public int X { get { return x; } set { x = value; } }
        public Sun this[int i] { get { return P[i]; } set { P[i] = value; } }
    }//father
    static public father[] xx = new father[3];//<--------------Line A
    // the line below is in Form_2_Load
         int SaveInt;
     saveInt = Form1.xx[0].P[0].V[0].X;
Posted
Updated 16-Apr-18 20:06pm
v6

C# is case sensitive; these two lines do not refer to the same variable:
int SaveInt;
saveInt = Form1.xx[0].P[0].V[0].X;

Fix that, and it'll compile.
It won't work - you'll get null reference errors because you haven't created any father instances in the array xx - but it'll compile.
You need to something like this as well:
C#
for (int i = 0; i < 3; i++)
   {
   xx[i] = new father();
   }
 
Share this answer
 
Comments
Engineer khalid 16-Apr-18 14:44pm    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace test
{
partial class Form1 : Form
{
public static FileStream fsG; StreamWriter sg;
class MyNum
{
private int x;
public MyNum() { }
public MyNum(int Xx) { X = Xx; }
public int X { get { return x; } set { x = value; } }
}//MyNum
class Sun
{
public int n;
public MyNum[] V;
public Sun() { }
public Sun(int Xn) { N = Xn; }
public int N { get { return n; } set { n = value; } }
public MyNum this[int i]
{ get { return V[i]; } set { V[i] = value; } }
}//MyLine
class father
{
public int x;//Number to be analysed like 256,128,64
public Sun[] P;
public father() { }
public father(int Xx) { X = Xx; }
public int X { get { return x; } set { x = value; } }
public Sun this[int i] { get { return P[i]; } set { P[i] = value; } }
}//father

static public father[] xx = new father[3];

public Form1() { InitializeComponent();}
//------------------------------------------------
private void FormLoad(object sender, EventArgs e)
{int i,j,k;

fsG = new FileStream("Tracey.txt", FileMode.Truncate, FileAccess.Write);
sg = new StreamWriter(fsG);//, System.Text.Encoding.Default);//for arabic file);

for (i = 0; i < 3; i++)// TO ANALYSE 3 NUMBERS like 256, 128 64
{
xx[i] = new father();//3 father
xx[i].X = 0;
xx[i].P = new Sun[4];//each father has four suns
for (j = 0; j < 4; j++)
{
xx[i].P[j] = new Sun(); //NUM,DIV,FACT,POWER each one has N which indicate how many NUM or DIV or FACT POWER
xx[i].P[j].N = 50; //each sun has 50 child
xx[i].P[j].V = new MyNum[50];//xx[i].P[j].N];//50 child
for (k = 0; k < xx[i].P[j].N; k++)
{
xx[i].P[j].V[k] = new MyNum();
xx[i].P[j].V[k].X = k;//each child has number`
}
}//j
}//for i
}

private void button1_Click(object sender, EventArgs e)
{
int i, j,k;
for (i = 0; i < 3; i++)// TO ANALYSE 3 NUMBERS
{
sg.Write("xx["+i.ToString()+"]="+"\r\n");
for (j = 0; j < 4; j++)
{
sg.Write("xx[" + i.ToString() + "].P[" + j.ToString() + "].N=" + xx[i].P[j].N.ToString()+"\r\n");
for (k = 0; k < 50; k++)
{
xx[i].P[j].V[k].X = k;
sg.Write("xx[" + i.ToString() + "].P[" + j.ToString() + "].V[" + k.ToString() + "].X=" + xx[i].P[j].V[k].X + "\r\n");
}//for k
}//j

}//for i
sg.Close(); fsG.Close();
MessageBox.Show("end");
}
Engineer khalid 16-Apr-18 14:45pm    
still not compiled
i should declare the class as public like
public class father
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900