Transform a DataTable into Dictionary C#

前端 未结 8 1860
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-02 07:13

I want to know how to transform a DataTable into a Dictionary. I did something like this.

using System.Linq;

internal Dictionary GetDict(Da         


        
8条回答
  •  温柔的废话
    2021-02-02 07:27

    All the previos answers didn't help me, so I did this:

    myList = dt.AsEnumerable()
    .ToDictionary(row => row[0].ToString(),
                                           row => row[1].ToString()); 
    

    and it worked great!

提交回复
热议问题