需要帮助打印字符串列表 [英] Need help print list of strings

查看:118
本文介绍了需要帮助打印字符串列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i am trying to print all innertext values for class xyz, but this is all i get printed "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());

推荐答案

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

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

这是因为System.Collections.Generic.List<T>不会重载ToString().默认实现(从System.Object继承)显示您所看到的对象类型的名称.

That is because System.Collections.Generic.List<T> does not overload ToString(). The default implementation (inherited from System.Object) prints the name of the object's type, which is what you are seeing.

您可能打算遍历列表中的所有元素,并分别打印每个元素.

You probably mean to iterate through all of the elements in the list, and print each separately.

您可以更改

Console.WriteLine(siteHome.getL1Names());

类似

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

这篇关于需要帮助打印字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆