c# - How to store a reference to a static class? -


so like:

public static class staticclass {}  public class instanceclass {     static staticclass staticproperty {get;set;}      public instanceclass()     {         instanceclass.staticproperty = staticclass;     } } 

i thought 1 compiler returns these errors:

static types cannot used parameters

static types cannot used return types

edit: know doesn't work, why? imagine staticclass stored somewhere in memory, other variables allowed refer @ same memory, right?

edit2: 1 of use cases this:

say have 5 different static classes have collected no source code, , generic stuff, want have convenient access them through single static class. like:

public static class genericstuff {     public linearalgebra linearalgebra {get;set;}     public stringutilities string {get;set;}     public geometryops geometry {get;set;} } 

and use like:

genericstuff.linearalgebra.getanglebetweenvectors(v0, v1); 

some other use cases think of.

update: going use psychic powers try , figure think you're trying do.

i'm guessing have static class methods want access within class. right?

something this, in other words:

static class helpermethods {     public static void somehelpermethod(); } 

...and want this?

class someotherclass {     public void methodthatuseshelpermethod()     {         // want able have "helper" mean "helpermethods"?         helper.somehelpermethod();     } } 

if i've interpreted correctly, there's 1 way (that can think) sort of accomplish you're after. add using declaration alias static type:

// @ top of file using helper = helpermethods; 

note if this, you're creating file-wide alias. there's no way alias classes @ class level.


staticclass name of class. staticproperty property expects instance of class, never exist because class static.

i'm surprised can have property typed static class, since represents total impossibility. (oh wait, can't that; that's saying.)

you want store "reference static class"; have assume mean want reference type object representing class, in case should this:

public type staticproperty { get; set; }  // ...  staticproperty = typeof(staticclass); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -