Summary Output of Pricing Information This function is used in a ASP.NET web application written in C#. It is heavily used to output summary information of the some prices chosen by a user. We are trying to lessen how much we have to scale horizontally.

Here is the original function:

    private static Dictionary&lt;int, string&gt; Cache = new Dictionary&lt;int, string&gt; {{ 1, "Adult" }, { 2, "Child" }};

    public string Build(List&lt;int&gt; priceTypeIds)
    {
        if (session == null)
        {
            return "";
        }

        var uniquePriceTypeIds = priceTypeIds.Distinct();

        var result = new List&lt;string&gt;();

        foreach (var priceTypeId in uniquePriceTypeIds)
        {
            var count = priceTypeIds.Count(x =&gt; x == priceTypeId);

            var description = Cache[priceTypeId];

            result.Add($"{count} {description}");
        }

        return string.Join(", ", result);
    }


I rewrote the function to eliminate the amount of string concatenations. But

private static Dictionary&lt;int, string&gt; Cache = new Dictionary&lt;int, string&gt; {{ 1, "Adult" }, { 2, "Child" }};

public static string CreateSummary()
{
    var sb = new StringBuilder();

    List&lt;int&gt; sample = new List&lt;int&gt; { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };

    foreach (var priceTypeId in sample.Distinct())
    {
        if (sb.Length &gt; 0)
        {
            sb.Append(',');
            sb.Append(' ');
        }

        sb.Append('(');
        sb.Append(Sample.Count(x =&gt; x == priceTypeId));
        sb.Append(')');
        sb.Append(' ');
        sb.Append(Cache[priceTypeId.ToString()]);
    }

    return sb.ToString();
}


The sample data in the second function is a common use case as we have classes get purchased with 20-30 kids in a single transaction along with chaperones.
It looks to me, that your problem could do with a bit more LINQ and the string concatenation operator.  Specifically the group clause.  Here's one way it could be done:

public static string Method2()
{
    List&lt;int&gt; sample = new List&lt;int&gt; { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };

    var data = String.Join(", ", (from int i in sample
                                 group i by i into g
                                 select $"({g.Count()}) {Cache[g.Key.ToString()]}"));

    return data;
}


The efficiency, I think would be better than what you have so far,the Distinct and each Count are extra iterations over the data, but, it would have to be tested to be sure. 

It definitely has the advantage of being more concise. 

Having the string format in one place makes it easier to see what's happening.

If you need the data parsed, instead of one long string, at some point, removing the String.Join part will leave an IEnumerable&lt;string&gt;.