mercredi 23 novembre 2016

How to replace multiple if statements i to more compact code/class in C#?

I`m having problem to convert multiple if statements, like the example below in to some more compact code. I though about tables or multidimensional arrays, but maybe you guys know some better solution. I have some 30 if statements in my code and there is no clear pattern in them in order to easily convert that code to something faster and more compact.

       if (D == 0.25)
        {
            if (threadPerInch == 20)
            {
                le = 0.22;
            }
            else if (threadPerInch == 28)
            {
                le = 0.25;
            }
            else if (threadPerInch == 32)
            {
                le = 0.28;
            }
            else
            {

            }
        }

Thank you

Thomas

Aucun commentaire:

Enregistrer un commentaire