: . , <, >, . .
==
I =
<
>
<=
>=
: == ! =, Object.EqualsO nObject. GetHashCode (). 11.
true false
true false . true false . if, while, for do-while ?.
true false , . .
public static bool operator true(_ )
{
// true false.
}
public static bool operator false(_ )
{
// true false.
}
, bool.
, true false ThreeD. : ThreeD , , , . .
// true false ThreeD. using System;
// , class ThreeD {
int , , z; //
public ThreeD() { = = z = 0; }
public ThreeD(int i, int j, int k) { x = i; = j; z = k; }
// true.
public static bool operator true(ThreeD op) { if((op.x!= 0) M (op.y!= 0) || (op.z!= 0))
return true; // else
Return false;
}
// false.
public static bool operator false(ThreeD op) { if((op.x == 0) && (op.y == 0) && (op.z == 0))
return true; //
Else
Return false;
}
// . public static ThreeD operator (ThreeD op)
{
ThreeD result = new ThreeD();
// , result.x = op.x - 1; result. = op.y - 1; result.z = op.z - 1;
Return result;
}
// X, Y, Z.
|
|
Public void Show ()
{
Console.WriteLine( + ", " + + ", " + z);
}
}
class TrueFalseDemo { static void Main() {
ThreeD a = new ThreeD (5, 6, 7);
ThreeD b = new ThreeD(10, 10, 10);
ThreeD = new ThreeD(0, 0, 0);
Console.Write(" a: ");
A.Show();
Console.Write(" b: ");
B.Show();
Console.Write(" : ");
C.Show();
Console.WriteLine();
if(a) Console.WriteLine(" ."); else Console.WriteLine(" .");
if(b) Console.WriteLine(" b ."); else Console.WriteLine(" b .");
if() Console.WriteLine(" ."); else Console.WriteLine(" .");
Console.WriteLine();
Console.WriteLine(" ThreeD."); do {
B.Show(); b;
} while(b);
}
}
.
: 5, 6, 7 : 10, 10, 10 : 0, 0, 0
b
ThreeD.
10, 10, 10
9, 9, 9 8, 8, 8 7, 1, 7 , 6, 5, 5, 5 4, 4, 4 3, 3, 3 2, 2, 2 1, 1, 1
, ThreeD if do-while. , if ThreeD true. , i f . do-while b . , , b , .. . , b , true .
, C# : &, |,!, & & | |. , , &, [ !. , , & & | |. .
. , & | , bool. , , !.
, !, & | ThreeD. , ThreeD , . , .
// //!, | & ThreeD.
Using System;
// . class ThreeD {
int , , z; //
public ThreeD() { = = z = 0; }
|
|
public ThreeD(int i, int j, int k) { x = i; = j; z = k; }
// |.
public static bool operator |(ThreeD opl, ThreeD op2)
{
if(((opl.x!= 0) M (opl.!= 0) M (opl.z!= 0)) I ((op2 .-x!= 0) || (op2. != 0) || (op2.z!= 0)))
Return true; else
Return false;
}
// &.
public static bool operator &(ThreeD opl, ThreeD op2)
{
if (((opl.x!= 0) && (opl.!= 0) && (opl.z!= 0)) & ((op2.x!= 0) && (op2.y!= 0) && (op2.z!= 0)))
Return true; else
Return false;
}
11 !. public static bool operator! (ThreeD op)
{
if ((op.x!= 0) M (op.!= 0) || (op.z!= 0))