Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

array sort C #

Array.Sort(array); // this will Modify original Array
Comment

array sort C Sharp

var sortedArray = arr.OrderBy(x => x); // OrderByDescending()
Comment

c# sort int array

 /// <summary>
        /// Sort Int Array
        /// </summary>
        /// <param name="sortBy">A- Ascendig, D- Descending order</param>
        /// <param name="arr">int array to sort</param>
        /// <returns>Sorted Array </returns>
/// Sorting without using the build sort in C# and using unlimited int array parameters using the params keyword
        public static int [] SortArray(char sortBy, params int [] arr)
        {
            int tmp;
            for(int x =0; x< arr.Length - 1; x++)
            {
                // traverse i + 1 
                for(int j =x + 1; j < arr.Length; j++)
                {
                    //compare and swap
                    if (sortBy.Equals('A'))
                    {
                        if (arr[x] > arr[j])
                        {
                            tmp = arr[x];
                            arr[x] = arr[j];
                            arr[j] = tmp;
                        }
                    }else if(sortBy.Equals('D'))
                    {
                        if (arr[x] < arr[j])
                        {
                            tmp = arr[x];
                            arr[x] = arr[j];
                            arr[j] = tmp;
                        }
                    }else
                    {
                        if (arr[x] > arr[j])
                        {
                            tmp = arr[x];
                            arr[x] = arr[j];
                            arr[j] = tmp;
                        }
                    }
                }
            }
            return arr;
        }
Comment

c# sort array

 int[] sortedCopy = from element in copyArray 
                    orderby element ascending select element;
Comment

c# sort array by value

// See https://aka.ms/new-console-template for more information
string[] myStrArr = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
int[] myIntArr = {5, 6, 4, 7, 85, 9, 2, 12, 3, 1};

// or use Array.Reverse() for DESC
Array.Sort(myStrArr);
Array.Sort(myIntArr);
// Array.Sort() for ASC

myStrArr.ToList().ForEach(i => Console.WriteLine(i.ToString()));
myIntArr.ToList().ForEach(i => Console.WriteLine(i));
Comment

PREVIOUS NEXT
Code Example
Csharp :: foreach for IEnumerable 
Csharp :: c# how to make object rotate forever 
Csharp :: C# Async Function with await 
Csharp :: unity how to check index of enum 
Csharp :: unity interface 
Csharp :: if or statement c# 
Csharp :: sql server query output to json file automatically 
Csharp :: fill dictionary c# 
Csharp :: convert json date to datetime c# 
Csharp :: open project in visual studio using command prompt 
Csharp :: by value by reference c# 
Csharp :: how to set the server url in dotnet core 
Csharp :: csv to xml using xmldocument c# 
Csharp :: c# run a scheduled task 
Csharp :: 2d explosion unity 
Csharp :: js if empty then 0 
Csharp :: c# sort array by value 
Csharp :: logical operators in c# 
Csharp :: vb.net read registry key as string 
Csharp :: how to make diagonal movement not double the speed of the player in unity 
Csharp :: discord bot c# how to refresh message 
Csharp :: SceneManagment by BuildIndex 
Csharp :: get one parameter from list in an new list c# 
Csharp :: Task timed out after 10.02 seconds 
Csharp :: photon 
Csharp :: c# ushort 
Csharp :: make first 2 words upper case c# 
Csharp :: c# set two dimensional array 
Csharp :: c# convert address to int 
Csharp :: C# Move Camera Over Terrain Using Touch Input In Unity 3D 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =