Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public class FullBucket
   {
       public string Type { get; set; }
       public double OpenAmt { get; set; }
       public double SubmitAmt { get; set; }
       public double NoOfClaims { get; set; }
       public double UniquePatient { get; set; }
   }


"_result" is the list which contains values shown below

Type	      OpenAmt	SubmitAmt	NoOfClaims	UniquePatient
31-60 Days     120	    2000	     235	      12
61-90 Days     110	    2000	    1254	      41
00-30 Days	   100	    2000	     248	      74
120+ Days	    90	    2000	     743	      24
91-120 Days	    80	    2000	     832	      41


i want to order it like this:

Type	     OpenAmt	SubmitAmt	NoOfClaims	UniquePatient
00-30 Days	    100	      2000	      248	    74
31-60 Days	    120	      2000	      235	    12
61-90 Days	    110	      2000	      1254	    41
91-120 Days	     80	      2000	      832	    41
120+ Days	     90  	  2000	      743	    24


I tried like this but its not working since "Type" is a string :( please help me to order it.

C#
List<FullBucket> _df = _result.OrderBy(d => d.Type).ToList();
Posted
Updated 6-Jan-16 2:45am
v2
Comments
Tomas Takac 6-Jan-16 8:54am    
If this is from database, you should show your query to populate _result as well.
[no name] 6-Jan-16 9:03am    
this is not from database. i have filtered this result from one more list.

List<fullbucket> _result = InfoDB
.GroupBy(l => l.AgingBucket)
.Select(cl => new FullBucket
{
Type = cl.First().AgingBucket,
OpenAmt = (double)cl.Sum(c => c.BalanceSubmitAmount),
SubmitAmt = (double)cl.Sum(c => c.SubmitAmount),
NoOfClaims = (double)cl.Select(l => l.ClaimNum).Count(),
UniquePatient = (double)cl.Select(l => l.PatientName).Distinct().Count(),
}).OrderBy(d => d.Type).ToList();

You may use Dictionary. See:

C#
Dictionary<string, int> orderOfType = new Dictionary<string, int>();
orderOfType.Add("00-30 Days", 0);
orderOfType.Add("31-60 Days", 1);
orderOfType.Add("61-90 Days", 2);
orderOfType.Add("91-120 Days", 3);
orderOfType.Add("120+ Days", 4);

var _result = _df.OrderBy(x=>orderOfType[x.Type]);
 
Share this answer
 
v2
Comments
[no name] 6-Jan-16 9:30am    
THANK YOU IT WORKED :)
Maciej Los 6-Jan-16 9:38am    
You're very welcome.
ridoy 6-Jan-16 14:34pm    
5ed.
Maciej Los 6-Jan-16 15:08pm    
Thank you.
If you are able to modify the FullBucket class, I would add a MinDays (int) property - and change the Linq/SQL to return a value for it.

If you are not able to modify it, can you derive a sub-class that expresses a MinDays property? In the sub-class, MinDays would be a get-only property, whose get expression is something like the following:
C#
public int MinDays
{
   get 
   {
	var minDaysText= (Type == null ? "" : Regex.Match(Type, "^[0-9]+").Value);
	minDaysText = string.IsNullOrEmpty(md) ? "99999" : minDaysText;
	return int.Parse(md);
   }
}

And, if you will be using MinDays regularly, you should add a nullable private field (int?), and set its value on the first reference ... so you don't have to do the regex on every reference.
 
Share this answer
 
Comments
Maciej Los 6-Jan-16 9:08am    
Very interesting, a 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