Answers for "sorting in c#"

C#
2

basic sorting algorithms c#

//Basic bubble sort
public static void IntArrayBubbleSort (int[] data)
      {
         int i, j;
         int N = data.Length;

         for (j=N-1; j>0; j--) {
            for (i=0; i<j; i++) {
               if (data [i] > data [i + 1])
                  exchange (data, i, i + 1);
            }
         }
      }
Posted by: Guest on March-12-2020
3

list sorting c#

using System.Linq;

//sorts in acending order {1,2,3,4,5}
myList.Sort();

//Sorts in decending order {5,4,3,2,1}
myList.Sort();
myList.Reverse();

//to sort a custom list of classes you have to 
//add this inside of your class
public int CompareTo(MyClass other)//replace MyClass with your class type
{
    //replace varInClass to the variable that you would like to compare
	return this.totalScore.CompareTo(other.varInClass)
}
Posted by: Guest on December-14-2020

C# Answers by Framework

Browse Popular Code Answers by Language