I have a list of Options. From that list:First I want to get only Drink (the where clause).Then I want to group them by their SortOrder (range of 100).I can stop there and loop through the items and create checkboxes for each items. But I got a requirement that if the OptionGroupName=Alcohol then I need to create radio list instead of checkboxes.Here's the code that does grouping using Linq:Option[] options = GetOptions();var groupedOptions = from option in options    where option.OptionType == OptionType.Drinks    group option by option.SortOrder / 100 into grouped    select new {     SortOrderGroup = grouped.Key,    GroupName = grouped.FirstOrDefault().OptionGroupName    ,SubGroup= grouped};Here's the JSON I get. That's what I want:So now I can check on client-side if GroupName=Alcohol generate radio buttons else generate checkboxes.[    {        SortOrderGroup: 3,        GroupName: Soft,        SubGroup: [            {                OptionId: 1,                DisplayName: Coke,                OptionType: 2,                SortOrder: 300,                OptionGroupName: Soft            },            {                OptionId: 2,                DisplayName: Pepsi,                OptionType: 2,                SortOrder: 301,                OptionGroupName: Soft            },            {                OptionId: 3,                DisplayName: Sprite,                OptionType: 2,                SortOrder: 302,                OptionGroupName: Soft            }        ]    },    {        SortOrderGroup: 4,        GroupName: Fruit,        SubGroup: [            {                OptionId: 4,                DisplayName: Apple Juice,                OptionType: 2,                SortOrder: 406,                OptionGroupName: Fruit            },            {                OptionId: 1,                DisplayName: Orange Juice,                OptionType: 2,                SortOrder: 400,                OptionGroupName: Fruit            }        ]    },    {        SortOrderGroup: 5,        GroupName: Alcohol,        SubGroup: [            {                OptionId: 2,                DisplayName: Wine,                OptionType: 2,                SortOrder: 501,                OptionGroupName: Alcohol            },            {                OptionId: 3,                DisplayName: Beer,                OptionType: 2,                SortOrder: 502,                OptionGroupName: Alcohol            },            {                OptionId: 4,                DisplayName: Rum,                OptionType: 2,                SortOrder: 520,                OptionGroupName: Alcohol            }        ]    }]
Grouping queries
c#;linq