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.

  1. 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 select 
  2. it's more readable when comes testing ranges:

    select case some_var case 1 10   something() case 20 30   something_else() case > 100   etc() end select 
  3. it'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 select 
  4. it's superior c/c++ switch in sense allows expressions branching points, not constants.

  5. when using constants branching points (example 1), compiler able generate more optimised code direct jumps.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -