c# - Can I store LINQ query result in an array? -


this code using linq, stores values list

string stringregex = "\"(?:[^\"\\\\]|\\\\.)*\"";          dictionary<string, string> dictionaryofstring = new dictionary<string, string>()         {             {"string", stringregex}         };   var matches = dictionaryofstring.selectmany(a => regex.matches(input,a.value)         .cast<match>()         .select(b =>                 new                 {                     index = b.index,                     value = b.value,                     token = a.key                 }))         .orderby(a => a.index).tolist();         (int = 0; < matches.count; i++)         {             if (i + 1 < matches.count)             {                 int firstendpos = (matches[i].index + matches[i].value.length);                 if (firstendpos > matches[(i + 1)].index)                 {                     matches.removeat(i + 1);                     i--;                 }             }         } foreach (var match in matches)         {             console.writeline(match);         } 

can not stored array? can display item want. here output {index=, value=, token=} meanwhile want output of "value" "token" index not needed.

you can use toarray instead. list gives desired array functionality already, can access item index.

var examplequrey = select c componentsdemo; var list = examplequrey.tolist(); var secondelement = list[1]; // <- demo only, there exception thrown, if there's less 2 elements in list 

edit: can see comments, need this:

foreach (var match in matches) {    console.writeline(match.value + ", " + match.token);  } 

Comments