I have a string like string strn = \"abcdefghjiklmnopqrstuvwxyz\"
and want a dictionary like:
Dictionary(){
{\'a\',0},
{
What am I doing wrong?
You're assuming there is such an overload. Look at Enumerable.ToDictionary - there's no overload which provides the index. You can fake it though via a call to Select
:
var dictionary = text.Select((value, index) => new { value, index })
.ToDictionary(pair => pair.value,
pair => pair.index);