using System;
using System.Collections;
namespace GenericApp
{
public class TestClass
{
// here int[] is return type
public int[] SortMyArray(int[] str1)
{
int i = 0;
int j = i + 1;
for (; i < (str1.Length - 1); i++)
{
for (int k = i + 1; k < (str1.Length - 1); k++)
{
if (str1[i] < str1[k])
{
continue;
}
else
{
int a = str1[k];
str1[k] = str1[i];
str1[i] = a;
}
}
}
return str1;
}
public static void Main(string[] aa)
{
TestClass obj = new TestClass();
// Define a int type of array which is unsorted
int[] mylist = { 22, 10, 1, 5, 3, 9, 2 };
// Check the out put before sorting
for (int i = 0; i < mylist.Length - 1; i++)
{
Console.WriteLine(mylist[i]);
}
// Check the out put after sorting
Console.WriteLine("\n After sorting int type array \n");
// Calling a method SortMyArray(mylist) which has return type as int array
// sorted the int type of array in method and override the sorted array into existing mylist array
mylist= obj.SortMyArray(mylist);
// display the sorted int array
for (int i = 0; i < mylist.Length - 1; i++)
{
Console.WriteLine(mylist[i]);
}
Console.ReadLine();
}
}
}