c# - How can I reference an List<string> object's position index without searching for first occurrence? -


i trying create xml document using linq , need reference index within list of each object. @ moment can find indexof(s) method returns first occurrence of s, rather position of s given. creates problem when list contains multiple copies of same value.

var commands = listprocedure.items.cast<string>().tolist();  var xdoc = new xdocument(     new xdeclaration("1.0", "utf-8", null),     new xelement("commands",                 commands.select(s => new xelement("command", s, new xattribute("id", commands.indexof(s)))                 ))); 

try 1

var commands = listprocedure.items.cast<string>().tolist();  var xdoc = new xdocument(     new xdeclaration("1.0", "utf-8", null),     new xelement("commands",                 commands.select( (s, idx) =>                      new xelement("command", s, new xattribute("id", idx))                 ))); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -