: . , . , , System Counter, .
using
using ( ) . :
using = ;
(, ) , . , .
, MyCounter Counter.CountDown.
// , using System;
// Counter.CountDown. using MyCounter = Counter.CountDown;
// , namespace Counter {
// , class CountDown { int val;
public CountDown(int n) { val = n;
}
public void Reset(int n) { val = n;
} '
public int Count() {
if(val > 0) return val ; else return 0;
}
}
}
class NSDemo4 {
static void Main() {
// MyCounter // Counter.CountDown.
MyCounter cdl = new MyCounter(10); int i;
do {
i = cdl... Count();
Console.Write(i + " ");
} while (i > 0);
Console.WriteLine ();
MyCounter cd2 = new MyCounter (20);
do {
i = cd2.Count ();
Console.Write (i + " ");
} while (i > 0);
Console.WriteLine ();
cd2.Reset (4); do {
i = cd2.Count ();
Console.Write (i + " ");
} while (i > 0);
Console.WriteLine ();
}
}
MyCounter .
using MyCounter = Counter.CountDown;
Counter. CountDown, . , CountDown.
MyCounter cdl = new MyCounter (10);
04 . . , Counter. CountDown, CountUp. Counter .
// , using System;
|
|
// Counter, using Counter;
// Counter.
namespace Counter {
// , class CountDown { int val;
public CountDown(int n) { val = n;
}
public void Reset(int n) { val = n;
}
public int Count() {
if(val > 0) return val; else return 0;
}
}
}
// Counter, namespace Counter {
// , class CountUp { int val; int target;
public int Target { get{
Return target;
}
}
public CountUp(int n) { target = n; val = 0;
}
public void Reset(int n) { target = n; val = 0;
}
public int Count() {
if(val < target) return val++;
Else return target;
}
}
}
class NSDemo5 {
static void Main() {
CountDown cd = new CountDown(10); CountUp cu = new CountUp(8);
int i; do {
i = cd.Count ();
Console^.Write (i + ";
} -while (i > 0);
Console.WriteLine ();
do {
i = cu.Count ();
Console.Write(i + " ");
} while(i < cu.Target);
}
}
.
10 9876543210 012345678
,
Using Counter;
Counter. CountDown CountUp , .. . Counter .