All the other answers are valid and nice,
I'm just trying to be original here. I often use the following technique in my code to improve readability and use "real words".
I usually spend "more time" on the naming, could be DocTypeIsValid, but I really like having my bool functions starting with "has" or "is". The point here is just to improve reusability and readability.
private bool IsDoctypeValid(string docType){
return docType == "PO" || docType == "II" || docType == "IT" || docType == "IV";
}
Note that you could use the technique found in other answers (the .Contains()
for example) and put it inside the return method, it works the same :) The idea i'm trying to point out is to extract your if
in a method, so you can do this later on, everywhere :
if (IsDoctypeValid(docType)){
}
which is super small and super readable.