[Solved] Reference data of Class B from another Class A in C# [closed]


You have a couple of points of confusion.

First, in Class A, the member variable Array 1 defaults to private access, so you cannot “see” it from Class B.

Secondly, good design would require you to present Array 1 as a property of Class A as follows:

class A
{
int[] array1;

public int[] TheArray
  {
    get { return array1; }
    set { array1 = value; }
  }
}

Then you could write:

class B

void myMethod() {
 int[] array2 = A.TheArray;
}

1

solved Reference data of Class B from another Class A in C# [closed]