X
xllx.relient.xllx
Hi, there. I need two simple things explained to me:
1.) I want to know why the "true" overloaded operator method gets
called with a test to a null-initialized instance:
public class AnimalClass
{
public static bool operator true( AnimalClass lhs )
{
Console.WriteLine("In true operator");
return true;
}
public static bool operator false( AnimalClass lhs )
{
Console.WriteLine("In false operator");
return false;
}
}
public class MainClass
{
public static void Main( )
{
AnimalClass A = null;
if ( A )
Console.WriteLine("true");
}
}
// output: In true operator
// is true
2.) How can you call the "false" operator method? because I've tried to
in many ways and I cannot get it to be invoked - only "true" works.
Thanks,
relient.
1.) I want to know why the "true" overloaded operator method gets
called with a test to a null-initialized instance:
public class AnimalClass
{
public static bool operator true( AnimalClass lhs )
{
Console.WriteLine("In true operator");
return true;
}
public static bool operator false( AnimalClass lhs )
{
Console.WriteLine("In false operator");
return false;
}
}
public class MainClass
{
public static void Main( )
{
AnimalClass A = null;
if ( A )
Console.WriteLine("true");
}
}
// output: In true operator
// is true
2.) How can you call the "false" operator method? because I've tried to
in many ways and I cannot get it to be invoked - only "true" works.
Thanks,
relient.