Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Can you check file extensions in a foreach in C#?

e.g. Is foreach(.exe in Applications){} possible?

2 Answers

Relevance
  • AJ
    Lv 7
    4 years ago
    Favorite Answer

    For what you have there, no

    You will need to use directoryInfo and FileInfo prior to the foreach loop

    DirectoryInfo di = new DirectoryInfo("C:\users\JDoe\"); (Folder location)

    FileInfo[] files = di.GetFiles("*.exe");

    foreach(FileInfo file in files)

    {

    }

  • Chris
    Lv 7
    4 years ago

    This is just another homework question. Great work.

    Anyway, think about it yourself. If you have an array of filenames read from a folder, could you check those names in a foreach loop...? Think hard. It's really not that difficult. Good luck.

Still have questions? Get your answers by asking now.