开发者

passing data from data set to a dictionary

开发者 https://www.devze.com 2023-03-24 00:28 出处:网络
Basically I have a data set with some data a data base table, I want to pass the data to a dictionary, what could be a good way yo accomplish my goal. Assuming that the dictionary have this structure

Basically I have a data set with some data a data base table, I want to pass the data to a dictionary, what could be a good way yo accomplish my goal. Assuming that the dictionary have this structure

Dictionary<int,string>

I'开发者_StackOverflow中文版m looking for some method to bind the rows of the dataset with the key and value of the dictionary.


Your question is pretty vague, if your dataset implements IEnumerable or IQueryable you can use the ToDictionary extension method:

Dictionary<int, string> dict = data.ToDictionary(e => e.id, e => e.name);
0

精彩评论

暂无评论...
验证码 换一张
取 消