© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
21 replies
Dyad

Better approach to grouping and ordering items?

Should containers be in charge of ordering, or the items themselves?

Approach 1:

class Item
{
  string GroupId;
  int GroupOrder;
}

var items = [...];
var groups = items.orderBy(x => x.GroupOrder).groupBy(x => x.GroupId);

This approach seems tedious if I want to reorder items, since I might have to update many items GroupOrder when moving one.

Approach 2:

class Group
{
  string Id;
  List<Item> Items;
}

var groups = new List<Groups>
{
  new Group { Id = "group.one", Items = ... },
  new Group { Id = "group.two", Items = ... },
  ...
} 

This approach seems easier to move items around, but involves manual entry into the Lists themselves
Should containers be in charge of ordering, or the items themselves?

Approach 1:

class Item
{
  string GroupId;
  int GroupOrder;
}

var items = [...];
var groups = items.orderBy(x => x.GroupOrder).groupBy(x => x.GroupId);

This approach seems tedious if I want to reorder items, since I might have to update many items GroupOrder when moving one.

Approach 2:

class Group
{
  string Id;
  List<Item> Items;
}

var groups = new List<Groups>
{
  new Group { Id = "group.one", Items = ... },
  new Group { Id = "group.two", Items = ... },
  ...
} 

This approach seems easier to move items around, but involves manual entry into the Lists themselves
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Idea for better approach for below problem?
C#CC# / help
4y ago
❔ "Items collection must be empty before using ItemsSource."
C#CC# / help
3y ago