6

I tried to use LINQ to convert one row to Dictionary (fieldName -> fieldValue)

return Enumerable.Range(0, reader.FieldCount)
                 .ToDictionary<string, object>(reader.GetName, reader.GetValue);

but I received error message:

Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable<int>' to 'System.Collections.Generic.IEnumerable<string>'

How to correct this?

Mike G
  • 4,232
  • 9
  • 40
  • 66
hellboy
  • 1,567
  • 6
  • 21
  • 54

1 Answers1

16
return Enumerable.Range(0, reader.FieldCount)
                 .ToDictionary(
                     i => reader.GetName(i),
                     i => reader.GetValue(i));
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
  • 1
    Isn't this doing exactly the same as the statement of the OP? Why would this not yield the same error? – fretje Feb 08 '21 at 17:46