This project is read-only.
1
Vote

using Static not in file scope

description

The following code doesn't works:
class Program
{
    static void Main(string[] args)
    {
        using System.Console;
        WriteLine("Hello");
    }
}
I would use this feature

comments

PauloMorgado wrote Oct 3, 2014 at 8:17 AM

Why should it work?

ry1a1 wrote Oct 4, 2014 at 5:58 AM

I think "using Static class" is useful not only on top of file

PauloMorgado wrote Oct 5, 2014 at 10:11 PM

Would you care to present comparative reasons on why this would be better than the current feature?

ry1a1 wrote Oct 6, 2014 at 5:48 AM

Goal is avoid pollution.

PauloMorgado wrote Oct 6, 2014 at 7:16 AM

C# features start with -1000 value points. Can you really award more than 1000 value points to this feature as you propose it?

What would be the scope of this? all lines of code following it? Can only be declared as the first instruction of the method?

Should it be a full blown using directive? That would be useful for extension methods.

KathleenDollard wrote Oct 6, 2014 at 5:58 PM

You can control using's scope via namespaces.

I agree this is a hack, but as namespaces can be repeated, you can have some control.

And to my knowledge, no one uses that feature.

So, I guess I wonder how much interest there would be at a method level, when there seems little interest at a namespace level.

Wouldn't a VB like "With" block be more helpful. A beefed up one that also handled statics. Among other things, it would allow a block, similar to allowing a using to go back out of scope within the same method.

Kathleen

PauloMorgado wrote Oct 6, 2014 at 10:19 PM

You could easily make it like this:
using (some type or namespace)
{
    // directive in effect
}
// directive no in effect.
But that would be a using directive that doesn't look like or behave like a using directive and it looks like a using statement but it's not.

If this where ever to be implemented, it would be better like the original proposal but applied to any code block:
{
    using System.Console;
    WriteLine("Hello");
}
But is that really worth the added development/maintenance complexity of the compiler/spec and the compiler code that has to run for every block with less then 99.9% chances of ever being used?

ry1a1 wrote Oct 8, 2014 at 3:47 AM

No. Of course not. If no one except me is going to use it, then this feature is unnecessary.