Android Question Dim variants?

Discussion in 'Android Questions' started by Troberg, Jun 12, 2015.

  1. Troberg

    Troberg Well-Known Member Licensed User

    I've seen two variants of assigning initial value to variables:

    Code:
    Dim x as int = 1
    Dim x = 1 as int
    Are these just two ways of doing the same thing, or is there any difference?
     
    wonder likes this.
  2. klaus

    klaus Expert Licensed User

    They are the same.
     
    Troberg, wonder and Peter Simpson like this.
  3. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    Being VB an inline programming lenguage, i think the compiler reads the whole line before translating it.

    the later is most used for several variables declarations

    Code:
    dim x = 1, z = 2 as int
     
    wonder likes this.
  4. Troberg

    Troberg Well-Known Member Licensed User

    Ah, I never thought of that option. I guess I'm to stuck in VB, where:

    Dim a, b as int

    means that a is a variant and b is an int.

    I just wanted to ask, to make sure that it didn't do anything that just looked the same, such as:

    Dim x = 1 as int

    would evaluate as:

    x casted to object
    1 casted to int
    x becoming an int as it was assigned 1
     
  5. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

  6. Troberg

    Troberg Well-Known Member Licensed User

    VB.Net, yes, but in VB6, a would be a variant.
     
  7. LucaMs

    LucaMs Expert Licensed User

    If you use the second version, could you have:
    dim x = a * 10 + 5 / floor(c).... As Int <---- murderess :D

    If so, it would be like a thriller: you can discover the murderess (type) only in the final :D

    I definitely prefer the first.
     
    Troberg likes this.
  8. Troberg

    Troberg Well-Known Member Licensed User

    Good point. I also use the first, mostly out of habit.
     
Loading...