【问题标题】:Need help print list of strings需要帮助打印字符串列表
【发布时间】:2015-01-30 01:25:05
【问题描述】:

我正在尝试打印 xyz 类的所有内部文本值,但这就是我打印的全部内容“System.Collections.Generic.List`1[System.String]

    public List<String> getL1Names()
    {

        UITestControl document = browinX.CurrentDocumentWindow;
        HtmlControl control = new HtmlControl(document);
        control.SearchProperties.Add(HtmlControl.PropertyNames.Class, "xyz");
        UITestControlCollection controlcollection = control.FindMatchingControls();
        List<string> names = new List<string>();
        foreach (HtmlControl link in controlcollection)
        {
            if (link is HtmlHyperlink)
            names.Add(control.InnerText);
        }
        return names;
    }

用它来打印

Console.WriteLine(siteHome.getL1Names());

【问题讨论】:

  • 感谢约翰·桑德斯

标签: c# visual-studio list return coded-ui-tests


【解决方案1】:

"System.Collections.Generic.List`1[System.String]

那是因为System.Collections.Generic.List&lt;T&gt; 没有重载 ToString()。默认实现(继承自 System.Object)打印对象类型的名称,这就是您所看到的。

您可能的意思是遍历列表中的所有元素,并分别打印每个元素。

你可以改变

Console.WriteLine(siteHome.getL1Names());

类似

foreach (var name in siteHome.getL1Names()) 
{
    Console.WriteLine(name);
}

【讨论】:

    猜你喜欢
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-31
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 2014-01-10
    相关资源
    最近更新 更多