lundi 27 juillet 2015

Which is more efficient? Is there any difference? c#

So let's say I have a generic model:

public class Model
{
    public int a { get; set; }
    public int b { get; set; }

    public Model()
    {
        int a = 0;
        int b = 0;
    }
}

Now I do a check on the values of that model - I can do it 2 ways:

if (model.a != 0 || model.b != 0)
    //do stuff

OR

if (model.a != 0)
    //do stuff
else if (model.b != 0)
    //do stuff

NOTE I realise the second option allows me to do alternate things depending on which is true, but in this example //do stuff is the same thing.

Which is the most efficient? Is there any difference?

Aucun commentaire:

Enregistrer un commentaire