Mark a method for static use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Mark a method for static use



How can I mark a method to use only if the class object was initialized as static?



For example:


public class A
{

public A()
{

}

public void DoIt()
{

{

public void DoItStatic()
{

}
}

public class B
{

private A _aa = new A();
private static A _aaStatic = new A();


public B()
{

}

public void SomeMethod()
{
_aa.DoItStatic(); //Generate Error for that.
_aaStatic.DoItStatic(); //it's fine
{

}



So, if someone tries to use _aa.DoItStatic(), where _aa is not initialized as static, we generate an error.



Is this possible?



Thanks!





You can't achieve that.
– mjwills
16 mins ago





So, there are no any options to make a check or anything else in class A?
– BERKUT
12 mins ago





How do you define "if the class object was initialized as static"? Consider this instance method code: var aClass = new A(); staticClass.aClass = aClass; - it was initialized in an instance method, but is being assigned to a static field. What is your motivation for doing this?
– john
6 mins ago




var aClass = new A(); staticClass.aClass = aClass;





This is feeling like a XY Problem - meta.stackexchange.com/questions/66377/what-is-the-xy-problem . Why do you want to do this?
– mjwills
4 mins ago







How do you define "if the class object was initialized as static"? I mean if it was initialized like - private static A _aaStatic = new A();
– BERKUT
30 secs ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

'Series' object is not callable Error / Statsmodels illegal variable name