简体   繁体   中英

Can I merge two IEnumerable<string> to IEnumerable<string,string>

I have two IEnumerable<string>

IEnumerable<String> titleCollection = htmlDoc.DocumentNode.SelectNodes("//h2[@class=
'entry-title']/a").Select(x => x.InnerHtml);

IEnumerable<String> allImages = htmlDoc.DocumentNode.SelectNodes("//div[@class=
'entry-thumbnail hover-thumb']/a/img").Select(x => x.Attributes["src"].Value);  

Is it possible to merge them to single IEnumerable<HTMLELEmsnts> .For sure there would be complications, but is there any way.

class HTMLElements
    {
        //private string _articeName;

        public string ArticleName { get; set; }
        public string ImageURL { get; set; }
    }

There's no such thing as IEnumerable<string, string> . IEnumerable<T> has only one type parameter.

But you can use Enumerable.Zip<TFirst, TSecond, TResult> to create an IEnumerable<Tuple<string, string>> or similar.

EDIT:

Based on the updated question, it seems you might want something like this:

IEnumerable<HTMLElements> Merge(IEnumerable<string> names, IEnumerable<string> urls)
{
    return names.Zip(urls, (name, url) => new HTMLElements(name, url));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM