OrderBy with lambda?

87 views Asked by At

I have following function to generate a table shown in the output screenshot. I want to modify this function to get desired output shown below but I am not very familiar with C#. If I pass years array into this function that consists of 3 items, how should I modify this function?

        private string GenerateHTML(string year)
        {
            var regions = RegionalList(year);
            if (!regions.Any()) return "";

            var rowHtmlString = regions.OrderByDescending(row => row.Capacity).Aggregate("", (current, row) => current + $@"
            <tr>
                <td>
                   <p>{row.Region}</p>
                </td>
                <td>
                   <p>{row.Percent.ToString("F1")}%</p>
                </td>
            </tr>
            ");
        return rowHtmlString;
        }

enter image description here

0

There are 0 answers