Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hellow i want to allocate a 2 dimension for a class that inhert from another class
C#
class class1
    {   private double a;
        public class1() { }
        public class1(double Xa)
        {   A    = Xa; }
        public double A
        { get { return a; } set { a = value; } }
	}
    
	class class2 : class1
    {   private double b;
        public class2() { }
        public class2(double Xa,   double Xb) : base(Xa)
        {   B    = Xb; }
        public double B
        { get { return b; } set { b = value; } }
	}


in Form1 my global declaration were
C#
class2[,] vary;


in Form1Load i create a 2 dimension like this
C#
class2[100,100] vary;

            for (i = 0; i < 100; i++)
                for (j = 0; j < 100; j++)
                vary[i, j] = new class2();
				vary[10,20].A=1;//<--------error
				vary[10,20].B=20;//<----   error


needs help
Posted
Updated 20-Sep-14 22:23pm
v3
Comments
Sergey Alexandrovich Kryukov 21-Sep-14 21:13pm    
The problem has nothing to do with "2 dimensions" and "allocation".
—SA

C# is a case sensitive language!
a (small a) and b (small b) are private member variables so can not be accessed from code outside the class itself...
Use your public properties A (capital A) and B (capital B)...
C#
vary[10,20].A = 1;
vary[10,20].B = 20
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Sep-14 21:13pm    
5ed.
—SA
Kornfeld Eliyahu Peter 22-Sep-14 2:19am    
Thank you!
a and b are private fields, use A and B instead which are public.
 
Share this answer
 
Comments
Engineer khalid 21-Sep-14 4:36am    
that is what i did... still error
Mehdi Gholam 21-Sep-14 4:45am    
... and what is the error?
Sergey Alexandrovich Kryukov 21-Sep-14 21:14pm    
5ed.
—SA
Mehdi Gholam 22-Sep-14 1:26am    
Thanks Sergey!

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