}
// Перегрузить оператор <.
public static bool operator <(Nybble op1, Nybble op2) {
if (op1.val < op2.val) return true; else return false;
}
// Преобразовать тип Nybble в тип int.
public static implicit operator int(Nybble op) {
return op.val;
}
// Преобразовать тип int в тип Nybble,
public static implicit operator Nybble(int op) {
return new Nybble(op);
}
}
class NybbleDemo {
static void Main() {
Nybble a = new Nybble(1);
Nybble b = new Nybble(10);
Nybble с = new Nybble();
int t;
Console.WriteLine("a: " + (int)a);
Console.WriteLine("b: " + (int)b);
if (a < b) Console.WriteLine("а меньше b");
// Сложить два объекта типа Nybble.
с = a + b;
Console.WriteLine("с после операции с = а + b: " + (int)с);
// Сложить значение типа int с объектом типа Nybble,
a += 5;
Console.WriteLine("а после операции а += 5: " + (int)a);
Console.WriteLine();