On 2007-11-21 00:01:47 -0800, Göran Andersson <(E-Mail Removed)> said:
> C# is object oriented, which means that all methods are inside classes.
> You can't declare any methods at ground level, as you could in C++.
>
> The using keyword saves you from specifying the namespace and class
> everytime you use a method, though.
Not quite. At least, not as you describe.
> If you have:
>
> namespace MyFancyLibrary {
>
> public static class UsefulUtilities {
>
> public static string GetSomeInfo() { ... }
> public static void DoSomethingCool() { ... }
>
> }
>
> }
>
> By putting:
>
> using MyFancyLibrary.UsefulUtilities;
>
> in your file, you can access the GetSomeInfo and DoSomethingCool
> methods directly.
You can't write the "using" directive as you've described it. Only a
namespace can go into the "using" directive in that way, not a class.
You can, however, create a class name alias with the "using" directive.
It wouldn't be very useful in this scenario, since the best you could
do is replace "UsefulUtilities" with something shorter (and frankly,
with Intellisense who cares how long a single identifier is?

). But
it could be done. For example:
using Utils = MyFancyLibrary.UsefulUtilities;
Then you could write:
Utils.GetSomeInfo();
Instead of:
MyFancyLibrary.UsefulUtilities.GetSomeInfo();
or instead of (if you included the namespace with "using"):
using MyFancyLibrary;
UsefulUtilities.GetSomeInfo();
But if you had a bunch of nested namespaces or classes, it could be
very useful since you could alias some long chain of nesting as a
single identifier.
Pete