I am having 2 lists. I should compare the 2 lists and should take the common value from both the list and i should put it 开发者_开发技巧in a string array...
First List....
List<string> IDs = new List<string>();
Dictionary<string, Test> group = TestProxy.GetNames(IDs.ToArray());
Second List...
List<string> Names = new List<string>();
Dictionary<string, Test> groupNames = TestProxy.GetSections(Names.ToArray());
How to take the common values...
Updated code....
List<string> IDs = new List<string>();
modulesIDs.Add("ID1");
Dictionary<string, Group> group = PrivilegeProxy.GetNames(IDs.ToArray());
List<string> Roles = new List<string>();
Roles.Add("Role1");
Dictionary<string, Role> Role = PrivilegeProxy.GetRoles(Roles.ToArray());
Dictionary<string, "******"> common = group.Intersect(Role).ToDictionary(x => x.Key, x => x.Value);
return common;
In the "common" Dictionary which object should i give ( " Dictionary common" )
Use Enumerable.Intersect
and Enumerable.ToDictionary
Dictionary<string, Test> commonGroups = group.Intersect(groupNames)
.ToDictionary(x=>x.Key, x => x.Value);
Update: Read this if doubt persists. Recreating a Dictionary from an IEnumerable
精彩评论