-13

I've an array sequence 20,40,60,10,30,50. I want to sort this sequence into the following order 60,40,50,20,30,10 in C#.

Any Help? Thanks in advance☺

3

3 Answers 3

1

Very Simple if you have an Array

int[] arr = { 1, 2, 3, 5, 9, 0, 2, 10 }; arr.OrderBy(a => a); arr.Reverse();

in case of list

List<int> abc = new List<int> { 1, 2, 3, 5, 9, 0, 2, 10 }; abc.Sort(); abc.Reverse();

Sign up to request clarification or add additional context in comments.

Comments

0

Just use OrderByDescending of LINQ:

var list = new[] {20, 40, 60, 10, 30, 50};
var newList = list.OrderByDescending(x => x);
Console.WriteLine(string.Join(",", newList)); //60,50,40,30,20,10

Comments

-1

You can try this

int[] array = new int[] { 20, 40, 60, 10, 30, 50 };
    Array.Sort<int>(array,
                    new Comparison<int>((element1, element2) => element1.CompareTo(element2)));

to reverse sort

element2.CompareTo(element1)

5 Comments

can you explain in briefly
@AmitMishra How is it working? the output is entirely different from what you have posted: "into the following order 60,40,50,20,30,10"
Sir can you provide me a answer using an example?
@AmitMishra can you provide exact rules for the sorting of the array?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.