将两个字典合并为一个字典<A,字典<B,列表<C>

时间:2019-10-16 07:46:16

标签: c# linq dictionary

假设我有两种字典:

  • Dictionary<A, List<C>>
  • Dictionary<B, List<C>>

我想将第二个合并到第一个中。就像是: Dictionary<A, Dictionary<B, List<C>>。在Linq中最好的方法是什么?

感谢您的帮助!

-

EDIT1: 考虑以下示例: `

public enum GameCategory
{
    FPS,
    RPG,
    STRATEGY
}

public class Game
{
    // The format is: "CountryName,CompanyName,TeamName,GameName"
    public string Name { get; set; } 
    public DateTime InitialReleaseDate { get; set; }
    public GameCategory Category { get; set; }
}
public class GameManager
{
    // CodeName is coming from Name once Substring applied.
    // This dictionary is just all the games grouped by this CodeName
    // eg if we have Game1 with name: "USA:Test:MyTeam:GoodGame" & Game2 with: "USA:Test:AnotherTeam:AnotherGame"
    // The codeName for both is: "USA:Test" so they are in the same list of dict1
    Dictionary<string, List<Game>> _gameByCodeName;

    // It is just a grouped by GameCategory
    Dictionary<GameCategory, List<Game>> _gameByCategory;

    // Expected output
    // The goal is just to have the two granularity in one data structure
    // In the above example it will be all the games that have the same CodeName and are in the same category     
    Dictionary<string, Dictionary<GameCategory, List<Game>>>
}

`

0 个答案:

没有答案