Demonstrate a using alias
// Demonstrate a using alias.
using System;
// Create an alias for Counter.CountDown.
using Count = Counter.CountDown;
// Declare a namespace for counters.
namespace Counter {
// A simple countdown 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;
}
}
}
public class NSDemo4 {
public static void Main() {
// Here, Count is used as a name for Counter.CountDown.
Count cd1 = new Count(10);
int i;
do {
i = cd1.count();
Console.Write(i + " ");
} while(i > 0);
Console.WriteLine();
Count cd2 = new Count(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();
}
}
Related examples in the same category