Write a program to sort one dimensional array in descending order using non static method

Write a program to sort one dimensional array in descending order using non static method.
Answer


using System;

namespace Sort_Array_Des
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int[] num= {22,50,11, 2, 49};
            Program p=new Program();
            p.SortArray(num);
        }

        public void SortArray(int[] numarray)
        {
            int swap = 0;
            for(int i=0; i<numarray.Length; i++)
            {
                for(int j=i+1; j<numarray.Length; j++)
                {
                    if(numarray[i]<=numarray[j])
                    {  
                        swap=numarray[j];
                        numarray[j]=numarray[i];
                        numarray[i]=swap;
                    }                    
                }
                Console.Write(numarray[i] + " ");
            }
        }
    }
}

output
50 49 22 11 2 _

More Example

Write A Program To Print One Dimensional Array In Reverse Order
Write A Program To Sort One Dimensional Array In Descending Order Using Non Static Method.
Write A Program To Sort One Dimensional Array In Desending Order Static Class Array Method.
Write A Program To Sort One Dimensional Array In Ascending Order Using Non Static Method.
Write A Program To Sort One Dimensional Array In Ascending Order Using Static Method.
Write A Program To Add The Diagonal Of Two-Dimensional Array.
 

Share your thought