Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do "CreateOrdredEnumerable" know what the sort keys of "OrderBy", and "IOrderedEnumerable" only two methods, No record of the order of elements with the same.How do "CreateOrderedEnumerable" work? :
<pre lang="cs">string[] fruits = { "ee","cc","aa", "ddd", "bbb","aaa" };
IOrderedEnumerable<string> sortedFruits2 =
    fruits.OrderBy(fruit => fruit.Length);
foreach (string fruit in sortedFruits2)
    Console.WriteLine(fruit);
//output:

//ee
//cc
//aa
//ddd
//bbb
//aaa

//"ee,cc,aa" have the same level sort."ddd,bbb,aaa" have the same level sort.
//now "CreateOrderedEnumerable" sort "ee,cc,aa" and "ddd,bbb,aaa".
//How do "CreateOrderedEnumerable " know the same sort of elements?
IOrderedEnumerable<string> sortedFruits3 =
    sortedFruits2.CreateOrderedEnumerable<string>(
        fruit => fruit,
        Comparer<string>.Default, false);
Console.WriteLine();
foreach (string fruit in sortedFruits3)
    Console.WriteLine(fruit);

Posted
Updated 16-Jul-10 18:24pm
v5
Comments
OriginalGriff 16-Jul-10 5:35am    
Nope. Don't understand a word of that.

Try to explain in better detail what you are trying to achieve, and what your problem is. Bits of that look like a C# problem other bits like an SQL problem.

Edit your question, and include a code fragment (using "code block" to preserve the formatting) that illustrates what your problem is.

1 solution

It looks like you're attempting to compare apples to oranges...

C#
IOrderedEnumerable<string> sortedFruits2 =
    fruits.OrderBy(fruit => fruit.Length);


Is ordering the array by string length, and I assume is using a normal string comparison (ie alphabetical) in a tie break.

C#
IOrderedEnumerable<string> sortedFruits3 =
    sortedFruits2.CreateOrderedEnumerable<string>(
        fruit => fruit,
        Comparer<string>.Default, false);


Your ordering the strings using the default comparison so you get an alphabetical ordering.
 
Share this answer
 
Comments
whoyousee 17-Jul-10 0:34am    
Forgive me for poor English,if CreateOrderedEnumerable<string> get an alphabetical ordering.why not out put:
aa
aaa
bbb
cc
ddd
ee

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900