I currently have
if A {
//code
return;
}
if B {
//code
return;
}
...
Is there a simple way to express this for a large number of conditions?
The goal in this case is validation of something that can fail in different ways, which all require different handling.
I then expect this block of code to be called again later, when whatever condition has just been resolved will fail, and it will slip through the tests until it meets another condition and is rejected in a new and exciting way.
I was really just hoping for something on the level of a switch statement (in terms of simplicity and ease of use) but I guess that doesn’t exist…
Possibly, but it’s really hard to guide you without knowing more about the types of conditions you have and what the code in each one does… if there are similarities, you can probably find ways to abstract those out instead of repeating them (using ‘switch’ statements, delegates, etc). If these things are totally unrelated, it won’t get any better than what you have shown – except to change latter ‘if’s to ‘else if’ and then put a single ‘return’ at the very end.