i was just curious about it that why we have to use an object of a class in order to access the class member? i mean i know we can access the static members without creating an object. But why can't we access the other class members without using objects? what is the actual mechanism behind this?
For Example, Take a look at the following code:
public class Taxi
{
public bool isInitialized;
public Taxi()
{
isInitialized = true;
}
}
class TestTaxi
{
static void Main()
{
Taxi t = new Taxi();
Console.WriteLine(t.isInitialized);
Console.ReadKey();
}
}
why we have to print the isInitialized variable using object and why can't we access it directoly?