Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I assign a static class to a variable?

Tags:

c#

My question is whether I can assign a static class to another variable (and of what type would that be) ?

Say I have

public static class AClassWithALongNameIDontWantTotType{
    public static bool methodA() { stuff }
}

and then I have

class B{

}

Can I make it so that inside of class B I can reassign this class to something with a shorter name, like:

SomeType a = AClassWithALongNameIDontWantTotType

and then be able to do

a.methodA()

?

I can get out a function by doing something like

Func<bool> a = AClassWithALongNameIDontWantTotType.methodA() 

but I would prefer to have the whole class.

Thanks!

like image 263
rafalio Avatar asked Dec 10 '22 07:12

rafalio


1 Answers

If you want this purely for the purpose of avoiding typing long names, you can use an alias

using a = SomeNamespace.AClassWithALongNameIDontWantToType;
like image 85
Mark H Avatar answered Jan 03 '23 05:01

Mark H