📜  从 ductionary 中按动态分组 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:58.687000             🧑  作者: Mango

代码示例1
private void GetValuesGroupedBy(List> list, List groupbyNames, List summableNames)
    {
        // build the groupby string
        StringBuilder groupBySB = new StringBuilder();
        groupBySB.Append("new ( ");
        bool useComma = false;
        foreach (var name in groupbyNames)
        {
            if (useComma)
                groupBySB.Append(", ");
            else
                useComma = true;

            groupBySB.Append("it[\"");
            groupBySB.Append(name);
            groupBySB.Append("\"]");
            groupBySB.Append(" as ");
            groupBySB.Append(name);
        }
        groupBySB.Append(" )");

        var groupby = list.GroupBy(groupBySB.ToString(), "it");
    }