Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

array sorting 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 :: unity audio 
Csharp :: unity c# get direction of object 
Csharp :: change image of button c# 
Csharp :: join two array c# 
Csharp :: .net core check if linux 
Csharp :: c# getting user input 
Csharp :: max value data annotation c# 
Csharp :: wpf arrow button 
Csharp :: how to create empty text file in c# 
Csharp :: build cs file 
Csharp :: datatable linq where clause c# 
Csharp :: calling stored procedure in c# entity framework 
Csharp :: dotnet automapper.extensions.microsoft.dependencyinjection 
Csharp :: system linq c# 
Csharp :: vector3 unity 
Csharp :: get color of pixel c# 
Csharp :: MissingPluginException (MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) 
Csharp :: multi line comment c# 
Csharp :: disable button in android studio 
Csharp :: c# round number up 
Csharp :: c# today without time 
Csharp :: if debug c# 
Csharp :: c# picturebox transparente 
Csharp :: get controller name from ActionExecutingContext .net 4.x 
Csharp :: pyautogui not odwnloading 
Csharp :: c# code skripte kommunizieren 
Csharp :: All Possible SubString of string 
Csharp :: split lines c# 
Csharp :: how to create function in c# 
Csharp :: order 3 integers in c# 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =