Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

In C# you can:

 

foreach(string s in MyStrings)

Console.WriteLine(s);

 

Note that s is declared on the spot, the closes I've been able to find for VB is the following:

 

Dim s As String

For Each s In MyStrings

Console.WriteLine(s)

Next s

 

I much rather have:

ForEach s as String In MyStrings

Console.WriteLine(s)

Next s

 

because all the extra Dim lines in the middle of a function just to do a loop looks, feels, and smells sloppy, but putting them at the top of the function just looks messy. There has to be away to declare and use a variable in a loop in VB. I've noticed the same issue with a regular for loop.

Posted (edited)

That's why it wouldn't work then...I have VB 2002. Will that work for iteration loop?

 

  For i As Integer = 1 To 10
 Console.WriteLine(i)
 Next i
  

(also how come my carriage returns aren't showing up in this code block?)

Thanks!

Edited by PlausiblyDamp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...