Click here to Skip to main content
15,922,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys anyone can pls suggest me..

I'm doing reporting
See i have five variable that is Tot1,Tot2,Tot3,Tot4,Tot5


i have some cal inside code behind

finally i got

ex:

Tot1=50;
Tot2=70;
Tot3=10;
Tot4=15;
Tot5=25;

I have sort first 4 place in descending order

Tot2
Tot1
Tot5
Tot4
Posted
Comments
Kenneth Haugland 4-Apr-13 5:28am    
WpF or WinForm?
snehal harawande 4-Apr-13 5:32am    
What are u looking for. or what you want to do.
Please write details.

You need to write code manually to sort individual variables.

For primitive type you can use below code - Descending Order
C#
var data = new[] { "a", "tar", "web", "coal", "sort" };
            data = data.OrderByDescending(x => x).ToArray();

            foreach (var item in data)
            {
                Console.WriteLine(item);
            }


Ascending Order
C#
var data = new[] { 4, 5, 6, 2, 1 };
            data = data.OrderBy(x => x).ToArray();

            foreach (var item in data)
            {
                Console.Write(item);
            }




but if you want to sort collection (reference type) then you can use IComparable and IComparer Interface.

Sorting Lists using IComparable and IComparer Interface in .NET[^]
 
Share this answer
 
This way also...
C#
int[] values = { Tot1, Tot2, Tot3, Tot4, Tot5 };
    Array array = values;
    Array.Sort(array);
string s = "";   
 for(i=4; i>0; i--)//reverse loop can give you desc order
    {
        s = s + array[i].ToString();
    }

Happy Coding!
:)
 
Share this answer
 
v2

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