For example, both System.Threading
and System.Timers
has the class Timer
. So if I would like to use System.Timers.Timer
in a class that uses System.Threading
, I have to use stuff like
System.Timers.Timer myTimer = new System.Timers.Timer();
everytime I want to declare/initialize timers. Is there a way to tell the compiler that "whenever I say Timer
, use System.Timers.Timer
unless declared otherwise?" So that I can use simple
Timer t = new Timer();
in default cases to mean System.Timers.Timer
, unless I specify explicitly
System.Threading.Timer t2 = new System.Threading.Timer();
You can create an alias for a type (or namespace). See using Directive (MSDN)
using TimersTimer = System.Timers.Timer;
....
var myTimer = new TimersTimer();
Yes.
using System.Threading;
using System.Timers;
using Timer = System.Timers.Timer;
Now Timer
refers to System.Timers.Timer
, but everything else from either namespace is still available without a prefix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With