Search code examples
c#c#-4.0streamopenfiledialog

Streamread an array C#


string [] filenames = openFileDialog1.FileNames;

How can I read this array?

Would I need to set each file path to its own string??? I'm clueless.


Solution

  • Do you mean access the elements in the array?

    for (int i = 0; i < filenames.Length; i++)
        MyDoSomethingMethod(filenames[i]);
    

    As pointed out by another answer you can also use a foreach to access each item

    foreach (String filename in filenames)
        DoSomething(filename);
    

    When you access filenames[some_index] you access the string already so there's no need to save it to another variable to work with it same applies to foreach loop.