08Dc91wk
08Dc91wk

Reputation: 4318

How to sort a List<DynamicTableEntity> a sealed class

I have a List of Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity that I need to sort. Although List provides me a Sort() method, DynamicTableEntity does not have a default comparator. As it is a sealed class, I can't seem to create my own.

I want to sort on DynamicTableEntity.RowKey.

What would be the most efficient way to sort this list? Should I roll my own sorting method or should I try to use some sort of Linq query, or is there something I'm missing?

Upvotes: 0

Views: 200

Answers (1)

Gimly
Gimly

Reputation: 6175

You should be able to use the Sort override that has the Comparison<T> delegate.

Something like this:

entities.Sort((x,y) => /*Code to compare your two entities */);

Knowing that the delegate should return an int with the following rule:

  • -1 if the first element should be before second (x < y)
  • 0 if they are equal
  • 1 if the first element should be after the second (x > y)

The simple types already implement a CompareTo method that you're likely to be able to use.

Upvotes: 2

Related Questions