Monday, 15 February 2010

c# - Can I merge two IEnumerable to IEnumerable -



c# - Can I merge two IEnumerable<string> to IEnumerable<string,string> -

i have 2 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 possible merge them single ienumerable<htmlelemsnts>.for sure there complications, there way.

class htmlelements { //private string _articename; public string articlename { get; set; } public string imageurl { get; set; } }

there's no such thing ienumerable<string, string>. ienumerable<t> has 1 type parameter.

but can utilize enumerable.zip<tfirst, tsecond, tresult> create ienumerable<tuple<string, string>> or similar.

edit:

based on updated question, seems might want this:

ienumerable<htmlelements> merge(ienumerable<string> names, ienumerable<string> urls) { homecoming names.zip(urls, (name, url) => new htmlelements(name, url)); }

c# linq ienumerable

No comments:

Post a Comment