Let’s say we’ve got 2 classes:
public class object1
{
string hehe = "xd";
void function()
{
if (x != 5) {} // here!
}
}
public class object2
{
int x;
int y;
object1 z;
}
I want to use x (From object 2) in a method in object1, which is stored in object2. Is that possible? I know, I can pass the data with method arguments but I’m wondering if its possible to avoid this somehow
To access a property within another class you would need to either pass the instant of the object, or the value itself. Alternatively if the property is static, you can access it on the class definition. You’ll also want to consider explicitly specifying the access modifier for your fields, properties and methods, so they’re more “visible”.