C
C#2y ago
Gladiator

❔ From which version, we can call non static methods in field declaration time?

I can call non static methods/props of an object in field declaration time. In which C# version, has it been added? Thanks
8 Replies
Gladiator
GladiatorOP2y ago
public float a=new Vector3(1,0,1).sqrMagnitude;
public float a=new Vector3(1,0,1).sqrMagnitude;
mtreit
mtreit2y ago
C# 1.0 ? Feel like I'm not understanding the question
Anton
Anton2y ago
definitely before c# 7 which any more or less modern unity version supports I think
333fred
333fred2y ago
Yeah, C# 1.0 sounds right Are you referring specifically to struct fields?
Gladiator
GladiatorOP2y ago
I think I explained badly. I have misled you In java, we can call non static methods inside that class but in C# we cannot
public class AA {
public int a = GetAA();

public int GetAA() {
return a;
}
}
public class AA {
public int a = GetAA();

public int GetAA() {
return a;
}
}
333fred
333fred2y ago
Yes, that is a common source of bugs in Java @Gladiator did you have any further questions? Or you want to $close the thread?
MODiX
MODiX2y ago
Use the /close command to mark a forum thread as answered
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server