tags:

views:

20

answers:

2

Suppose we declare and define the variable in one class let say FirstClass and we want to use that variable in another class let say SecondClass which is outside of FirstClass .how to do this?

+1  A: 
  1. Declare the variable as internal
  2. Inherit the class
Bala
A: 

First, an OBJECT of class FirstClass needs a reference to an object of SecondClass. It can get this via a set-Method, as a constructor argument or by creating it by itself.

Then either this variable is public/internal or wrapped by a public/internal getter, then you can access it:

  class A 
  { 
    private int v; 
    public int Var { get { return v; } }
  }

 class B
  { 
     public void DoSomething() { A a = new A(); Console.Write(a.Var);}
  }
Philipp