Questions tagged [iorderedenumerable]

21 questions
37
votes
3 answers

Is it possible to turn an IEnumerable into an IOrderedEnumerable without using OrderBy?

Say there is an extension method to order an IQueryable based on several types of Sorting (i.e. sorting by various properties) designated by a SortMethod enum. public static IOrderedEnumerable OrderByX(this IQueryable values, …
NominSim
  • 8,447
  • 3
  • 28
  • 38
31
votes
3 answers

When to return IOrderedEnumerable?

Should IOrderedEnumerable be used as a return type purely for semantic value? For example, when consuming a model in the presentation layer, how can we know whether the collection requires ordering or is already ordered? What about in the case that…
fearofawhackplanet
  • 52,166
  • 53
  • 160
  • 253
14
votes
1 answer

How does IOrderedEnumerable.ThenBy() in .Net work?

I want to understand how ThenBy works in .Net. (I know how to use it, I just don't understand how Microsoft implemented it!) According to the documentation, string_list.OrderBy(Function (x) x.length).ThenBy(Function (x) x) should output a list of…
Eyal
  • 5,728
  • 7
  • 43
  • 70
11
votes
1 answer

Will IOrderedEnumerable.Select() retain element order?

In C#, will using Select() to project the elements of an IOrderedEnumerable retain element order? If so, how come it returns an IEnumerable, and not an IOrderedEnumerable? If not, how can I achieve this (other than using foreach)? Note that this…
bavaza
  • 10,319
  • 10
  • 64
  • 103
5
votes
2 answers

Can it be advantageous for a method to return IOrderedEnumerable instead of IEnumerable?

Can it be advantageous for a method to return IOrderedEnumerable instead of IEnumerable?
Jim G.
  • 15,141
  • 22
  • 103
  • 166
4
votes
3 answers

Why doesn't IOrderedEnumerable re-implement .Contains() to gain performance

If you go here: The IOrderedEnumerableDocs and click on the .Contains() method then it takes you to here: the generalised Enumerable.Contains() docs I take this to mean that it's just using the underlying IEnumerable implementation? This seems…
Brondahl
  • 7,402
  • 5
  • 45
  • 74
3
votes
1 answer

Removing an object from IOrderedEnumerable

I sorted a dictionary like this: var sortedListOfNodes = _nodeDictionary.Values.OrderBy((n) => n.Time); Then I selected an element as such: var selectedNode = sortedListOfNodes.First(n => n.Time - CurrentTime > new TimeSpan(1,0,0)); Then I did…
Anders
  • 580
  • 8
  • 17
3
votes
1 answer

How does Linq use IEnumerable methods after an IOrderedEnumerable method?

In Linq, extension methods like Where return an IEnumerable collection, but sorting methods like OrderBy return an IOrderedEnumerable collection. So, if you have a query that ends with OrderBy (i.e. returns an IOrderedEnumerable), you can't later…
Graham Clark
  • 12,886
  • 8
  • 50
  • 82
3
votes
2 answers

Sorting with OrderBy, ThenBy

I'm trying to sort several columns of a table depending of the previous sorted column. It works fine for the first two columns. But as soon as I sort the third column the second one loses its sort. As far as I know for now there must be a problem…
Daniel
  • 31
  • 5
2
votes
4 answers

Strange behaviour of OrderBy Linq

I have a list which is ordered using the OrderBy() Linq function, that returns an IOrderedEnumerable. var testList = myList.OrderBy(obj => obj.ParamName); The ParamName is an object that can hold integer as well as string. The above orderBy orders…
Krishna P S
  • 340
  • 2
  • 9
2
votes
0 answers

How to simply convert an IEnumerable into IOrderedEnumerable in O(1)?

Is there a way to simply convert an IEnumerable into an IOrderedEnumerable in O(1)? I've seem this question which is close to mine, but haven't found what I'm looking for. By simply, I mean to avoid creating a new class just for this casting…
AXMIM
  • 2,424
  • 1
  • 20
  • 38
2
votes
1 answer

IOrderedEnumerable and defensive programming

I'm fond of defensive programming. I hate exception throwing, but this is not the subject of my question. I adapted an extension to linQ to be able to perform an order by with a column name public static IEnumerable OrderBy(this…
Mose
  • 1,781
  • 3
  • 16
  • 35
1
vote
1 answer

Improve query performance to order records by Linq-to-SQL

I'm using a query to get records from a table named customers and I want to order the records by address, housenumber, surname, name. First I used this (DataTable) public CustomerInfo.customers GetCustomers(string zipcode) { string sql =…
1
vote
3 answers

Can I add a where clause to an IOrderedEnumerable list?

I have a list of arrays. Each array consists of a score and a difficulty. Read in from a text file. This is how I get the data and order it by the score in descending order. // load highscores public void LoadScores() { // loop through each line…
crmepham
  • 4,676
  • 19
  • 80
  • 155
1
vote
4 answers

How intelligent is Linq with IOrderedEnumerable and Where

so let's say I have an IEnumerable dates and I want to get the dates within a range. Is Linq and IOrderedEnumerable intelligent enough to realize the ability to choose faster algorithms given that the dates are now ordered. So consider…
Anders Miltner
  • 253
  • 3
  • 12
1
2