Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to display data in order

C#
string msg="TS,AP,8,7,6,5,KA,4,2,11,K,CD1,9,3,12,10,1";

string ordertext = string.Join(",",msg.Split(',').Distinct().ToArray().OrderBy(x=>x.Any()));


can you guide me or send snippets
Posted
Updated 29-Apr-15 22:10pm
v3

1 solution

Basically you got it right. Two remarks though:
1) no need for ToArray(): why to materialize the IEnumerable when you are going to order it?
2) The Any() in order by doesn't make sense. You just want to order by the actual items.
C#
string.Join(",",msg.Split(',').Distinct().OrderBy(x=> x));

I was confused a short while why Any() works on strings. Then I realized that String implements IEnumerable<Char> :)
 
Share this answer
 
Comments
Maciej Los 30-Apr-15 4:11am    
+5!
Karthik_Mahalingam 30-Apr-15 5:01am    
clean solution, good +5

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