c# - What to use in the blank space in order to add the "x" variable from class A without creating another object of A? -


i have use this keyword in order add 3 values of x present in 3 classes.

i not allowed create instance of class a in method m1.

class program {     static void main(string[] args)     {         c c = new c();         int op = c.m1();         console.writeline(c.x);         console.writeline();          } } public class {     public int x = 10; } public class b:a {     public int x = 100;  } public class c:b {     public int x = 1000;     public int m1()     {         return (x + base.x + _____ );          //what use in blank space in order          //add "x" variable class without          //creating object of     } } 

}

cast current instance (this) a. can use

((a)this).x

heres complete code of method, how define it

public int m1() {     return (x + ((b)this).x + ((a)this).x );  } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -