Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

array sorting C Sharp

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 :: unity sound 
Csharp :: streamwriter c# 
Csharp :: c# list object sort alphabetically 
Csharp :: c# get application root path directory 
Csharp :: c# int array 
Csharp :: string to camel case c# 
Csharp :: dns ttl meaning 
Csharp :: xmldocument to c# object 
Csharp :: c# add object to array 
Csharp :: how to run a c# program 
Csharp :: sorting a list of objects in c# 
Csharp :: unity custom editor 
Csharp :: asp.net core mvc jsonresult example 
Csharp :: unity find gameobject with layer 
Csharp :: asp.net model 
Csharp :: c# get total milliseconds from datetime 
Csharp :: postasjsonasync reference c# 
Csharp :: unity get center of object 
Csharp :: use raycast unity new input system 
Csharp :: c# array of class 
Csharp :: unity camera follow with lerp 
Csharp :: check if an object is active unity 
Csharp :: c# swap name in string 
Csharp :: blazor ref to component in if 
Csharp :: c# read large file 
Csharp :: bsod screen c# 
Csharp :: all Substring of String 
Csharp :: c# remove the last character of a string 
Csharp :: c# replace multiple characters 
Csharp :: carousel asp.net mvc beginner 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =