Results 1 to 2 of 2

Thread: for each equivalent

  1. #1

    Thread Starter
    Hyperactive Member Sneeden's Avatar
    Join Date
    Oct 2001
    Location
    Sneedville
    Posts
    258

    for each equivalent

    in vb.net you can do this
    VB Code:
    1. Files = IO.Directory.GetFiles(TargetDir, "*.*")
    2.         lstFiles.Items.Clear()
    3.         For Each File In Files
    4.             lstFiles.Items.Add(File)
    5.         Next

    what is the syntax to do this in c#?

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    PHP Code:
            public void LoadDirectoryFiles(string targetDir)
            {
                
    DirectoryInfo dr = new System.IO.DirectoryInfo(targetDir);
                
    FileInfo[] fi dr.GetFiles();
                foreach(
    FileInfo f in fi)
                {
                    
    lstSearchResult.Items.Add(f);
                }
            }

            private 
    void button1_Click(object senderSystem.EventArgs e)
            {
                
    LoadDirectoryFiles(@"e:\");
            } 
    //DirectoryInfo and FileInfo are part of System.IO.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width