Click here to Skip to main content
15,885,979 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a list of string
for example :
Trunk=2*12
Trunk=2*1
Trunk=2*2

I want sort it by IComparable in c# .

How to do it ?
Posted

1 solution

String already supports IComparable, just sort it like this:
C#
using System;

public class Program
{
    public static void Main()
    {
        string[] strArray = new string[]
        {
           "Trunk=2*12", "Trunk=2*1", "Trunk=2*2"
        };

        Array.Sort(strArray);
        foreach (string s in strArray)
        {
            Console.WriteLine(s);
        }
    }
}

Read more: How to use the IComparable and IComparer interfaces in C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900