M
mijalko
Look at this code:
class test
{
private bool bInitialized = false;
private string strTest;
public string str2 = "";
private void Init()
{
if (bInitialized)
return;
bInitialized = true;
strTest = str2;
}
public test()
{
strTest = "";
bInitialized = false;
}
public string StrTest
{
get
{
Init();
return strTest;
}
}
public override string ToString()
{
Init();
return strTest;
}
}
class Program
{
static void Main(string[] args)
{
test t = new test();
t.str2 = "AAAA";
Console.WriteLine(t.StrTest);
Console.ReadLine();
}
}
Problem is in overriding ToString() method. Program will execute
Init() from ToString() and you will not be able to see that in
debuger. You can even change back bInitialized to false in constructor
but in next step Init() from ToString() will be called and you will
not see that in debuger. Why debuger does not show this call?
class test
{
private bool bInitialized = false;
private string strTest;
public string str2 = "";
private void Init()
{
if (bInitialized)
return;
bInitialized = true;
strTest = str2;
}
public test()
{
strTest = "";
bInitialized = false;
}
public string StrTest
{
get
{
Init();
return strTest;
}
}
public override string ToString()
{
Init();
return strTest;
}
}
class Program
{
static void Main(string[] args)
{
test t = new test();
t.str2 = "AAAA";
Console.WriteLine(t.StrTest);
Console.ReadLine();
}
}
Problem is in overriding ToString() method. Program will execute
Init() from ToString() and you will not be able to see that in
debuger. You can even change back bInitialized to false in constructor
but in next step Init() from ToString() will be called and you will
not see that in debuger. Why debuger does not show this call?