【问题标题】:Unable to Print Anonymous type variable's values无法打印匿名类型变量的值
【发布时间】:2019-02-25 03:02:10
【问题描述】:

我已经迭代了

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

我想在 tmp_variable 中打印 Name

在“自动”选项卡中(调试变量值时),tmp_variable 具有以下值: tmp_variable { 路径 = "D:\abc\folder1", 名称 = "folder1" }

但无法使用任何此类东西。

我试过写

    MessageBox.Show(tmp_variable[Name]);

和,

    MessageBox.Show(tmp_variable.Name);

但是没有任何效果。一切都显示错误。

【问题讨论】:

标签: c# winforms


【解决方案1】:

我希望这会有所帮助。

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));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多