In VB.NET why should I use Select, instead of If? -
i've graduated , started real job. in our training they've been exposing vb.net , lot of features use here. in of examples, they've used select statements (and in few places used if/else should have been used).
the time i've used switch/select statement in other languages (other assignments required it) has been when wanted fall through next statement.
given vb.net has no fall through, (if any) cases there use select statement? there cases when provides advantages on , if/elseif statement?
select case, not select.
me, it's 1 of best features of language.
it's more visual when have several possible values test against.
select case some_var case 1 something() case 2 something_else() case 3 etc() end selectit's more readable when comes testing ranges:
select case some_var case 1 10 something() case 20 30 something_else() case > 100 etc() end selectit's more readable when have bunch of more complex conditions test, making sure 1 selected:
select case true case string.isnullorempty(a_string) something() case a_string.length < 5 something_else() case a_string = b_string etc() end selectit's superior c/c++
switchin sense allows expressions branching points, not constants.when using constants branching points (example 1), compiler able generate more optimised code direct jumps.
Comments
Post a Comment