using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ajuniv
{
class Program
{
static void Main(string[] args)
{
List<string> li1 = new List<string>();
li1.Add("bcbb");
li1.Add("abc");
li1.Add("bbaa");
li1.Add("aa");
Console.WriteLine("Before sorting");
foreach (var item in li1)
{
Console.WriteLine(item);
}
li1.MySortFunction();
Console.WriteLine("After sorting");
foreach (var item in li1)
{
Console.WriteLine(item);
}
}
}
public static class MyListFunction
{
public static void MySortFunction(this List<string> li)
{
string temp;
for (int i = 0; i < li.Count; i++)
{
for (int j = 0; j < li.Count; j++)
{
if (string.Compare(li[i], li[j])<0)
{
//Swap
temp = li[i];
li[i] = li[j];
li[j] = temp;
}
}
Console.WriteLine("..................................");
foreach (var item in li)
{
Console.WriteLine(item);
}
Console.WriteLine("..................................");
}
}
}
}
Please post if you have any questions in the below comment section so that we will help you out with the solution or other viewers of this post will may also help you.
No comments:
Post a Comment