Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: Is it possible to return an IOrderedEnumerable<T>?

Is it possible to return an IOrderedEnumerable<T> from a method without using the OrderBy or OrderByDescending methods on an IEnumerable<T>?

Im guessing perhaps not... but... maybe I am wrong?


Reason: Mostly curiosity. It just kind of hit me when making this answer on returning digits in a number. And my method would return the digits in ascending order, according to their weight in the given number. So I thought it could be nice if they came out ordered in a way that the framework would recognize as ordered as well. Of course we can argue that from a common number point of view they were not ordered. But yeah... if they should or shouldn't wasn't the point here. Just if it was possible or not.

I guess I am also kind of implying a question (or am now at least) on if an IOrderedEnumerable<T> is more than just an IEnumerable<T> with a different name. Does it contain anything more? i know it has the ThenBy and ThenByDescending methods, but do they use anything inside the IOrderedEnumerable<T>, or is it just that they don't make sense to use directly on an IEnumerable<T>?

like image 634
Svish Avatar asked May 06 '09 13:05

Svish


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


1 Answers

Well, you can implement IOrderedEnumerable<T> yourself if you want too... it's not hugely hard, depending on what you need to do. The easiest option is just to call OrderBy/OrderByDescending though :)

Why are you interested?

like image 143
Jon Skeet Avatar answered Oct 07 '22 15:10

Jon Skeet