I am trying to make sense of the new VB.Net suite after using VB6 for some time. I have just tried an example from a Wrox book that works fine but I can’t quite understand. The example is shown below.
What I don’t understand is the line:-
objSubFolders = New DirectoryInfo(“C:\”).GetDirectories
I can see the objSubFolders DirectoryInfo object is populated by the statement starting with ‘New’. But my dim mind can’t grapple with why the compiler does not accept the statement:-
objSubFolders(“C:\”).GetDirectories
ObjSubFolders is a DirectoryInfo object so why does it not behave like a direct execution of the DirectoryInfo.
General Declarations
‘
‘ Import NameSpace With All Classes Below It
‘ Including DirectoryInfo
Imports System.IO
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
‘
‘ Define Object
Dim objSubFolders() As DirectoryInfo ‘
‘
‘ Define Instance
objSubFolders = New DirectoryInfo(“C:\”).GetDirectories
Dim objSubFolder As DirectoryInfo
For Each objSubfolder In SubFolders
lstListBox1.Items.Add(subfolder.FullName)
Next
End Sub
What I don’t understand is the line:-
objSubFolders = New DirectoryInfo(“C:\”).GetDirectories
I can see the objSubFolders DirectoryInfo object is populated by the statement starting with ‘New’. But my dim mind can’t grapple with why the compiler does not accept the statement:-
objSubFolders(“C:\”).GetDirectories
ObjSubFolders is a DirectoryInfo object so why does it not behave like a direct execution of the DirectoryInfo.
General Declarations
‘
‘ Import NameSpace With All Classes Below It
‘ Including DirectoryInfo
Imports System.IO
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
‘
‘ Define Object
Dim objSubFolders() As DirectoryInfo ‘
‘
‘ Define Instance
objSubFolders = New DirectoryInfo(“C:\”).GetDirectories
Dim objSubFolder As DirectoryInfo
For Each objSubfolder In SubFolders
lstListBox1.Items.Add(subfolder.FullName)
Next
End Sub