LupusRex
Member
- Joined
- Oct 30, 2019
- Messages
- 16
- Programming Experience
- Beginner
Hi
As I already have said before I'm all new to C#, so sorry if this is a noob question.
Is there any special reason/performance improvement by using "if, if else" over "if, if, if."?
Like this:
My reason for asking this is, that I have a lot of validations to make, where I use if statements due to the lack of select statements in C# (I know that select and if doe's the same, but I find that select statements is more readable, that a lot of if statements), and a switch statement don't work in this case.
Ohh, and what is the different between using {} and not in if statements (I've seen both types, when I search for coding answers).
Cheers
/LR
As I already have said before I'm all new to C#, so sorry if this is a noob question.
Is there any special reason/performance improvement by using "if, if else" over "if, if, if."?
Like this:
C#:
if (a) {
// Do something.
}
else if (b) {
// Do something else
}
else if (c){
// :)
}
// Only if statements
if (a) {
// Do something.
}
if (b) {
// Do something else
}
if (c){
// :)
}
My reason for asking this is, that I have a lot of validations to make, where I use if statements due to the lack of select statements in C# (I know that select and if doe's the same, but I find that select statements is more readable, that a lot of if statements), and a switch statement don't work in this case.
Ohh, and what is the different between using {} and not in if statements (I've seen both types, when I search for coding answers).
Cheers
/LR