Let's say you have this:
// Overload true.
public static bool operator true(ThreeD op) {
if((op.x != 0) || (op.y != 0) || (op.z != 0))
return true; // at least one coordinate is non-zero
else
return false;
}
// Overload false.
public static bool operator false(ThreeD op) {
if((op.x == 0) && (op.y == 0) && (op.z == 0))
return true; // all coordinates are zero
else
return false;
}
public class TrueFalseDemo {
public static void Main() {
ThreeD a = new ThreeD(5, 6, 7);
ThreeD b = new ThreeD(10, 10, 10);
ThreeD c = new ThreeD(0, 0, 0);
Console.Write("Here is a: ");
a.show();
Console.Write("Here is b: ");
b.show();
Console.Write("Here is c: ");
c.show();
Console.WriteLine();
if(a) Console.WriteLine("a is true.");
else Console.WriteLine("a is false.");
if(B)/> Console.WriteLine("b is true.");
else Console.WriteLine("b is false.");
if(c) Console.WriteLine("c is true.");
else Console.WriteLine("c is false.");
I am just stuck with the false operator since it is not even used in the program if assuming a, the object, is always true. Besides, that how do we know what codes to write in the overload false operator method as the overload true operator already does the job true and false. If it is true returns true if false, returns false.
This post has been edited by kenryuakuma: 02 March 2010 - 04:36 PM

New Topic/Question
Reply




MultiQuote







|