c# - How to use reverse in foreach of XmlNodeList? -


i want data in reverse foreach

here xmlnodelist comments = d.selectnodes("//comments/comment/creator");

i've 4 values,i want reverse it

i've written code

 public void commentm4(string pstid, string cmtid)     {         xmldocument d = new xmldocument();         d.loadxml(content);          xmlnodelist comments = d.selectnodes("//comments/comment/creator");         foreach (xmlnode xncomment in  comments)         {             commentmemberid = xncomment["id"].innertext;             dbconnection.open();             dbcommand = new oledbcommand("select count(response_id)  mw_response customer_id = '" + commentmemberid + "' , post_id='" + pstid + "'", dbconnection);             oledbdatareader dbreader = dbcommand.executereader();              while (dbreader.read())             {                 count = dbreader[0].tostring();                 cnt = convert.toint32(count);                 if ((cnt == 0) && (comments1 != ""))                 {                     dbcommand = new oledbcommand("update mw_response set prod_id = (select prod_id mw_post post_id='" + pstid + "'),customer_id = (select customer_id mw_customer customer_id='" + commentmemberid + "') response_id = '" + cmtid + "'", dbconnection);                     dbcommand.executenonquery();                 }             }             dbreader.close();             dbconnection.close();         }     } 

any ideas? in advance.

use for loop instead, starts @ last element, , works way first.

if (comments.count > 0) {     (int = (comments.count - 1); >= 0; i--)     {      xmlnode xncomment = comments[i];     //rest of logic...     } } 

update: i've added if-block make sure loop runs if there more 1 element in collection.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -