0

I have iterated

foreach (var tmp_variable in all_subdirectories)
{
    MessageBox.Show(tmp_variable["Name"]);
}

I want to print the Name inside tmp_variable .

In the Autos tab (While Debugging the variable value), the tmp_variable has the following values: tmp_variable { Path = "D:\abc\folder1", Name = "folder1" }

But unable to use any of such things.

I have tried writing

    MessageBox.Show(tmp_variable[Name]);

and,

    MessageBox.Show(tmp_variable.Name);

But nothing works. Everything shows error.

enter image description here

Thompson
  • 1,954
  • 10
  • 33
  • 58
  • Please do not post screenshots of error messages (something to read: [Pictures of exceptions are not helpful](http://idownvotedbecau.se/imageofanexception/)). –  Feb 24 '19 at 18:49
  • Possible duplicate of [Working with C# Anonymous Types](https://stackoverflow.com/questions/3935711/working-with-c-sharp-anonymous-types) –  Feb 24 '19 at 18:52

1 Answers1

0

I hope this helps.

var all_subdirectories = System.IO.Directory.GetDirectories(folderPath);

foreach (var tmp_variables in all_subdirectories)
{
    // Get the directory name only from filepath
    MessageBox.Show(System.IO.Path.GetFileName(tmp_variables));
}
Jozsef Baksa
  • 104
  • 4