jeudi 8 janvier 2015

What is the best way to write multiple if tags that compare two variables

I am a beginner in C# coding, and I was trying to compare two int variables (C#).



void CompareNumber() {
int oneNumber;
int secondNumber;

if (oneNumber > secondNumber)
{
DoSomething();
}

else if (oneNumber < secondNumber)
{
DoSomething();
}

else if (oneNumber == secondNumber)
{
DoSomething();
}
}


While this does work, it looks kinda messy, especially because I compare variables in this manner many times. Is there a more concise way of doing this, making it look neater? (Except for omitting the curly brackets)


Aucun commentaire:

Enregistrer un commentaire