passing data from data set to a dictionary
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);
精彩评论