We cannot access a private variable of a class from an object, which is created outside the class, but it is possible to access when the same object is created inside the cl
You Can Access the private variables in the following process also...
namespace OOPSProj
{
class Program
{
private int i;
public void Methode1()
{
Program objprog2 = new Program();
objprog2.i = 15;
Console.WriteLine("i= " + objprog2.i);
}
static void Main(string[] args)
{
Program objprog = new Program();
objprog.i = 10;
Console.WriteLine("i= " + objprog.i);
objprog.Methode1();
}
}
class Test
{
static void Main()
{
Program objproj3 = new Program();
objproj3.Methode1();
}
}
}