mercredi 30 mai 2018

Returning If-Else Result Independent of If-Else Order?

If I had the following code:

string x = "123";
string y = "abc";

if (stringVar.Contains(x))
{
    return x;
}
else if (stringVar.Contains(y))
{
    return y;
}

where

string stringVar = "123abc";

it would

return x;

However

stringVar = "abc123";

would also

return x;

Is there a way where instead of following the pre-defined order of the if-else statement, I could have the return result be based upon the order of stringVar instead?

My desired result is if:

stringVar = "123abc";
...
return x;

and if:

stringVar = "abc123";
...
return y;

Aucun commentaire:

Enregistrer un commentaire