c# sort for loop
public static void Main(string[] args)
{
int[] arr = { 5,4,3,2,1 };
Sorting(arr);
}
public static void Sorting(int[] arr)
{
int length = arr.Length;
for (int i = 0; i < length - 1; i++)
{ //length-1 b/c i+1 will put you OOB
if (arr[i] > arr[i + 1])
{//For descending order...skips to next index if false
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
i = -1; //sort from lowest out of order index
}
}
foreach (int item in arr)
{
Console.WriteLine(item);
}
}
Also in C#:
- copy a list C#
- c# shorten an method
- c# list tuple
- c# EncoderParameter
- unity set material color
- unity prevent system from creation
- how to convert object in string JSON c#
- how to add movement in unity
- what does gameobject.find return
- top down movement unity
- c# add object to array
- how to name GameObject in c#
- unity 2d detect click on sprite
- c# Sleep
- pop up element from specific index in array
- c# keyvaluepair
- c# try catch error
- c# transform
- unity draw wire square
- Assets\playermove.cs(30,37): error CS1003: Syntax error, ',' expected
- unity reset scene
- read file line by line c#
- c# razor add disabled to button if
- how to convert string to bool c#