Alias for static member in C#?
alias, c#, static-members
Solution
C# doesn't allow you to create aliases of members, only of types. So the only way to do something like that in C# would be to create a new property which is accessible from that scope:
class Program
{
static string MyMember
{
get { return MyClass.MyMember; }
set { MyClass.MyMember = value; }
}
static void Main(string[] args)
{
MyMember = "Some value.";
}
}
It's not really an alias, but it accomplishes the syntax you're looking for.
Of course, if you're only accessing / modifying a member on `MyClass`, and not assigning to it, this can be simplified a bit:
class Program
{
static List<string> MyList = MyClass.MyList;
static void Main(string[] args)
{
MyList.Add("Some value.");
}
}
Problem
I have a static member: ``` namespace MyLibrary { public static class MyClass { public static string MyMember; } } ``` which I want to access like this: ``` using MyLibrary; namespace MyApp { class Program { static void Main(string[] args) { MyMember = "Some value."; } } } ``` How do make `MyMember` accessible (without `MyClass.`) to `MyApp` just by adding `using MyLibrary`?