As I always repeat, this good or bad practice depends on context. In this case without knowing all the requirements of what you are doing you have no way to respond. Both are correct and acceptable.
If you make the second to get shorter, more funny, in thesis save typing, then do not do, it does not make sense. Especially in C # which privileges compilation time.
The second one passes a run-time processing to resolve something that could have been resolved at compile time. Leave Contains()
to cases where you do not know what the data list is, or it can be changed frequently, or if it is too large, which does not seem to be close at all.
If C # had some optimization that would guarantee that Contains()
would be linearized and then unrolled, which probably would generate more or less the same code as the first, there could even do. It has language that has an operator for this which generates an optimized code.
But if you have no worries about runtime, you can do it, though I do not recommend it.
But you have to analyze the context, if it makes sense to produce a list, because this is what you are manipulating, which does not seem to be the case, make a list. If it is not a list, the most readable is the first. If it's a list, I do not know if it should be created there in if
, probably it should be somewhere else. Do what you want best, what ever is the intention.