Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

array sort CSharp

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# remove all punctuation from string 
Csharp :: c# excel close workbook 
Csharp :: c# remove all whitespaces from string 
Csharp :: limiting the amount of decimal places c# 
Csharp :: unity sort a list 
Csharp :: how to validate if date is a weekday or weekend c# 
Csharp :: check if an object is active unity 
Csharp :: c# alphabetize a list of string 
Csharp :: how to get row index of selected row in gridview asp.net webforms 
Csharp :: how to stop a form c# 
Csharp :: how to filter a datatable in c# 
Csharp :: how to destroy parent gameobject unity 
Csharp :: input unity 
Csharp :: c# encrypted 
Csharp :: unity yield return 
Csharp :: unity tilemap get all tiles 
Csharp :: the same schemaid is already used for type swagger 
Csharp :: wasd code for unity 
Csharp :: how to get an arrays length in c# 
Csharp :: c# yield 
Csharp :: wpf how to focus on element 
Csharp :: c# make file not read only 
Csharp :: Metadata publishing for this service is currently disabled 
Csharp :: how to turn components on and off in unity through code 
Csharp :: npm add auth token 
Csharp :: color32 unity 
Csharp :: expando object c# 
Csharp :: c# list foreach lambda multiple actions 
Csharp :: convert string to decimal c# 
Csharp :: checkbox in c# 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =