Storing two List<strings> into the properties of a collection object issue c# -
hi trying store 2 list have been populated already, collection objects, collection named "specialoffers" , require first string list set 1 of properties , other string list other, having issues inserting these lists collection create new specialoffers objects in collection. appreciated.
new scraping html content off webpage, , trying store content in collection defined using specialoffers model seen below, both properties values first stored in 2 string lists, 1 image property , 1 body property, then insert these 2 lists values properties in specialoffers collection.
model class (specialoffers):
using system; using system.collections.generic; using system.linq; using system.web; using system.drawing.imaging; namespace redseaexample.models { public class specialoffers { public specialoffers(string image, string body) { this.image = image; ; this.body = body; } public string image { get; set; } public string body {get; set;} } } **class retrieve image sources , table html source** public collection<models.specialoffers> capturelinks(string source, collection<models.specialoffers> specialofferscollection, htmldocument html) { int = 0; list<string> bodylist = new list<string>(); list<string> getstring = new list<string>(); list<list<string>> table1 = html.documentnode.selectsinglenode("//table[1]").descendants("tr").skip(1).where(tr => tr.elements("td").count() > 1). select(tr => tr.elements("td").select(td => td.innertext.trim()).tolist()).tolist(); var table = html.documentnode.selectnodes("//table[1]").firstordefault(); foreach (list<string> txt in table1) { foreach (string example in txt) { getstring.add(example + (i + 1).tostring()); } bodylist.addrange(table.selectnodes("..//img/@src").select(t => t.outerhtml + (i + 1).tostring())); specialofferscollection.add(bodylist); //(new specialoffers(bodylist.tostring(), getstring.tostring())); } return specialofferscollection; }
i'm not totally sure understand you're trying accomplish, can construct list of special offers parallel lists using .zip()
.
specialofferscollection.addrange( bodylist.zip(getstring, (b, g) => new specialoffers(b, g));
Comments
Post a Comment