Re: Interesting Results In VB.Net
- From: "Tom Shelton" <tom@xxxxxxxxxxx>
- Date: 25 Apr 2006 10:29:34 -0700
Mythran wrote:
"Tom Shelton" <tom@xxxxxxxxxxx> wrote in message
news:1145976995.312423.256840@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Larry Lard wrote:
Mythran wrote:
For i As Integer = 0 To 5
Dim sb As StringBuilder
If i = 0 '1
sb = New StringBuilder(i.ToString()) '1
Next i
Console.WriteLine(sb.ToString()) '2
Next i '3
The above code gives the following output:
No, the above code does not compile. What did you actually run?
Errors:
1: If without End If
2: 'sb' not declared (because the scope it was in was closed by the
previous line)
3: Next without For
Add the "Then" to the if statement, and it compiles just fine (well, as
long as you import System.Text).
--
Tom Shelton [MVP]
Grr...
1: If DOES NOT REQUIRE a "Then" keyword. Try it and find out ;)
Doh! Your right it is optional in VB.NET. I guess, I never realized
it because VS just automatically adds it - and it used to be required
in VB5/6. I'm glad they made it optional...
2: The code DOES compile if you change the first instance of "Next i" to
"End If" .. my mistake on that.
I never noticed it... I just typed your code into VS - so it just did
it :)
3: See #2 for that fix.
Sorry, that's what I get for typing off top of head...I hate how OE tries to
re-format my code when I copy and paste, so I either open notepad and do 2
copies/pastes, or just type off top of head..
It is a pain that...
--
Tom Shelton [MVP]
.
- References:
- Interesting Results In VB.Net
- From: Mythran
- Re: Interesting Results In VB.Net
- From: Larry Lard
- Re: Interesting Results In VB.Net
- From: Tom Shelton
- Re: Interesting Results In VB.Net
- From: Mythran
- Interesting Results In VB.Net
- Prev by Date: Re: Warning from Setup Project: Two or more objects have the same target location
- Next by Date: Re: GetType question
- Previous by thread: Re: Interesting Results In VB.Net
- Next by thread: Re: Interesting Results In VB.Net
- Index(es):
Relevant Pages
|
|