Where or when would one would use namespace aliasing like
using someOtherName = System.Timers.Timer;
It seems to me that it would just add more confusion to understanding the language.
Meskipun C dibuat untuk memprogram sistem dan jaringan komputer namun bahasa ini juga sering digunakan dalam mengembangkan software aplikasi. C juga banyak dipakai oleh berbagai jenis platform sistem operasi dan arsitektur komputer, bahkan terdapat beberepa compiler yang sangat populer telah tersedia.
C adalah huruf ketiga dalam alfabet Latin. Dalam bahasa Indonesia, huruf ini disebut ce (dibaca [tʃe]).
Bahasa pemrograman C ini dikembangkan antara tahun 1969 – 1972 oleh Dennis Ritchie. Yang kemudian dipakai untuk menulis ulang sistem operasi UNIX. Selain untuk mengembangkan UNIX, bahasa C juga dirilis sebagai bahasa pemrograman umum.
That is a type alias, not a namespace alias; it is useful to disambiguate - for example, against:
using WinformTimer = System.Windows.Forms.Timer; using ThreadingTimer = System.Threading.Timer;
(ps: thanks for the choice of Timer
;-p)
Otherwise, if you use both System.Windows.Forms.Timer
and System.Timers.Timer
in the same file you'd have to keep giving the full names (since Timer
could be confusing).
It also plays a part with extern
aliases for using types with the same fully-qualified type name from different assemblies - rare, but useful to be supported.
Actually, I can see another use: when you want quick access to a type, but don't want to use a regular using
because you can't import some conflicting extension methods... a bit convoluted, but... here's an example...
namespace RealCode { //using Foo; // can't use this - it breaks DoSomething using Handy = Foo.Handy; using Bar; static class Program { static void Main() { Handy h = new Handy(); // prove available string test = "abc"; test.DoSomething(); // prove available } } } namespace Foo { static class TypeOne { public static void DoSomething(this string value) { } } class Handy {} } namespace Bar { static class TypeTwo { public static void DoSomething(this string value) { } } }
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