Is there any in-built stable sort routine in .NET?
I know that C++ has an in-built sort routine under “algorithms” std::sort(). Likewise, do we have something to use along with C#?
Also, is there any in-built swap function in .NET?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using “C# stable sort” in Google revealed this SO post as top result:
Is the sorting algorithm used by .NET's `Array.Sort()` method a stable algorithm?
So the answer is:
Enumerable.OrderByis a stable sort function, not built into C#, but part of the .NET framework libraries.Concerning “Swap”: I don’t know of any prebuilt generic swap function in the .NET framework, but here you find an implementation in less than 10 lines of code: