Talk:Visual Basic .NET/Variables

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Regarding default data types. In the Using Variables section it mentions the following (incorrect?) examples... bytMyVariable = 1 sbytMyVariable = -2 ... intMyVariable = 100

I find this kinda confusing. how does the compiler know if its sposed to be a byte, sbyte or integer? it cant tell only based on the value coz the value 1 and 100 is valid for all (byte, sbyte and integer) and the value -2 is valid for both sbyte and integer. It mentions in the previous paragraph: "Integral literals, such as 42 and 1000, are of type Integer by default" So according to this all three (bytMyVariable, sbytMyVariable and intMyVariable) should be of type integer. am i right? assuming that is correct, it also implies that it is impossible to have a variable of type byte or sbyte w/o an explicit type declaration statement like: Dim bytMyVariable As Byte = 1 or Dim sbytMyVariable As SByte = -2. Any thots?