This question was
closed Sep 04, 2016 at 07:53 AM by
Hellium for the following reason:
This is not a Unity question, but a pure programming-related one, and thus, does not belong to Unity Answers
Question by
Adolfo_Morgado · Sep 04, 2016 at 07:51 AM ·
if-statementsmethods
C# What is more efficient, If Statement inside Method or Method Inside of If Statement
So I have a question, which of these 2 following Options is more efficient?
void Start(){
if(condition){
method();
}
}
void method(){
//statements
}
Or
void Start(){
method();
}
void method(){
if(condition){
//Statements
}
}
Thanks in advance!
Comment
This is not a Unity question, but a pure program$$anonymous$$g-related one, and thus, does not belong to Unity Answers.
If all the statements inside your method are executed only if the condition is satisfied, then, you should put the condition outside the method. Thus, you will avoid a useless additional function in your stack : https://en.wikipedia.org/wiki/Call_stack