1

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" )

RobinHood
  • 2,367
  • 11
  • 46
  • 73

1 Answers1

4

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

Community
  • 1
  • 1
naveen
  • 53,448
  • 46
  • 161
  • 251