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 :: c# get enum name from value 
Csharp :: overridable method C# 
Csharp :: how to add object in dictionary in c# 
Csharp :: wpf app transparent background with blurred image affect 
Csharp :: how to get the dynamic year for your web app in mvc 
Csharp :: c sharp type in word and calculate how much a letter is inside that word 
Csharp :: c# how to refresh input field 
Csharp :: VBNet dictionary for each 
Csharp :: C# varible 
Csharp :: dotnet core clickable row 
Csharp :: csharp-for-loop 
Csharp :: difference between iqueryable and ienurable 
Csharp :: deferred rendering unity 
Csharp :: decode token to get claims value 
Csharp :: asp.net core 6 get current culture in controller 
Csharp :: Photon Register Callbacks 
Csharp :: c# execute after delay 
Csharp :: sortdescriptions wpf 
Csharp :: c# UserControl make background transparent 
Csharp :: devexpress aspxdatagridview set VerticalScrollableHeight in codebehind 
Csharp :: != in f# 
Csharp :: How to add a button to a column in the DataGridView 
Csharp :: c# convert address to int 
Csharp :: take the last 50 from array c# 
Csharp :: c# order of initialization 
Csharp :: rename join table in many to many 
Csharp :: unity get object position on screen 
Csharp :: "??" in C# 
Csharp :: unity generate random offset position around a gameobject 
Csharp :: c# how to load type of class from string 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =