The using
keyword has three disparate meanings:
- type/namespace aliasing
- namespace import
- syntactic sugar for ensuring Dispose is called
The documentation calls the first two definitions directives (which I'm guessing means they are preprocessing in nature), while the last is a statement.
Regardless of the fact that they are distinguished by their syntaxes, why would the language developers complicate the semantics of the keyword by attaching three different meanings to it? For example, (disclaimer: off the top of my head, there may certainly be better examples) why not add keywords like alias
and import
? Technical, theoretical, or historical reasons? Keyword quota? ;-)
Contrived sample:
import System.Timers;
alias LiteTimer=System.Threading.Timer;
alias WinForms=System.Windows.Forms;
public class Sample {
public void Action() {
var elapsed = false;
using(var t = new LiteTimer.Timer(_ => elapsed = true) {
while (!elapsed) CallSomeFinickyApi();
}
}
}
"Using" is such a vague word.