Reputation:
Assume in a winform application we have in program.cs
:
static class Program
{
public static SomeClass someClass;
[STAThread]
static void Main()
{
//something
}
}
so to use someClass
in other classes in current Project we should access Program.someClass
the question is can we make an alias for Program.someClass
like for example c1
and use c1
in code instead of Program.someClass
?
Upvotes: 9
Views: 9438
Reputation: 2004
Assuming that you want to achieve something like macros in C/C++ and also want to get rid of "Program" as naming scope, I think you cannot do that in C#.
Upvotes: 3
Reputation: 36319
If you're just looking to alias it for wrist-friendliness, do it as an inline delegate, like this:
Func<SomeClass> c1 = () => Program.someClass;
But I agree that it makes your code less clear in most cases.
Upvotes: 7