Is it possible to make an alias for a variable in C #?

Suppose in a winform application we have program.cs:

static class Program
{
    public static SomeClass someClass;

    [STAThread]
    static void Main()
    {
        //something
    }
}

therefore, for use someClassin other classes in the current Project, we must accessProgram.someClass

The question is, can we make an alias for Program.someClass, for example, for example c1, and use c1in the code instead Program.someClass?

+5
source share
3 answers

If you're just looking for an alias for user convenience, do it as a built-in delegate, for example:

Func<SomeClass> c1 = () => Program.someClass;

But I agree that in most cases your code becomes less clear.

+6
source

, - C/++, "" , , #.

+2

Just pass this object to every class that needs to work with it

+1
source

All Articles