Posts

Showing posts with the label non-static

I need to reference a variable from a non static class in a non static class constructor. [c#]

I need to reference a variable from a non static class in a non static class constructor. [c#] I'm trying to make a solar system with natural satellites. Currently I'm drawing a planets relative to a static "Sun" class object, but i wold like to make the class use a position of another planet object and draw relative to that planet. To do that i need to extract the x and y position of that planet object. This is the class constructor of a class i use for drawing planets. Nebesko_Telo merkur = new Nebesko_Telo(Sun.x, Sun.y, 4, 12, 4.090909090909091, 1, 255, 255, 255); // A field initializer cannot reference the non-static field, method, // or property 'Form1.merkur'. Nebesko_Telo venera = new Nebesko_Telo(merkur.x, merkur.y, 1, 23, 1.5, 1, 176, 108, 32); This is the class constructor. public Nebesko_Telo(doubl _rel_tel_x, double _rel_tel_y, double _r, double _or, double _Fi_mult, double _tilt_plant_n...