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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -