Maybe you can found this my code useful.
The first is converting list to dictionary with key-selector.
The second extracts only two atributes (key, val)
Code Snippet
- class People
- {
- public string userID { get; set; }
- public string name { get; set; }
- public string phone { get; set; }
- public string email { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<People> users = new List<People>();
- //p.Add()...
- Dictionary<string, People> temp =
- users.ToDictionary(c => c.userID);
- Dictionary<string, string> eMails =
- users.ToDictionary(c => c.userID, c => c.email);
- }
- }
Žiadne komentáre:
Zverejnenie komentára