Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6757265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:37:38+00:00 2026-05-26T13:37:38+00:00

class Program { static void Main(string[] args) { //Period 01 2008, Period 02 2008

  • 0
class Program
{


    static void Main(string[] args)
    {

        //Period 01 2008, Period 02 2008
        Series s1 = new Series { Text = "Period 01 2008", Value = "1"};
        Series s2 = new Series { Text = "Period 02 2008", Value = "2" };
        Series s3 = new Series { Text = "Period 03 2008", Value = "3" };

        Series s11 = new Series { Text = "Period 01 2009", Value = "1" };
        Series s21 = new Series { Text = "Period 02 2009", Value = "2" };
        Series s31 = new Series { Text = "Period 03 2009", Value = "3" };

        Series s12 = new Series { Text = "Period 01 2010", Value = "1" };
        Series s22 = new Series { Text = "Period 02 2010", Value = "2" };
        Series s32 = new Series { Text = "Period 03 2010", Value = "3" };

        List<Series> series = new List<Series> { s21, s31, s1, s12, s11, s2, s22, s3, s32 };


       // mySeries.ForEach(i => Console.WriteLine("Period {0} {1}",i.Period, i.Year));
        series.ForEach(i => Console.WriteLine(i.Text));

        Console.WriteLine("************************");

        series.OrderBy(i => i.Text);

        series.ForEach(i=> Console.WriteLine(i.Text));

    }

}


public class Series
{
    public string Text { get; set; }
    public string Value {get;set;}
}

Basically I want my list to be ordered by the Text property of the Series class. I have a work-around by splitting the text, but I am looking for any other way – using IComparer maybe?

The ordered list should be something like this:

Period 01 2008, Period 02 2008, Period 03 2008, Period 01 2009,
Period 02 2009…

Update: the definition of the Series class cannot be changed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:37:39+00:00Added an answer on May 26, 2026 at 1:37 pm

    Add following comparer

    public class SeriesTextComparer : IComparer<string>
    {
        public int Compare(string x, string y)
        {
            string[] xparts = x.Split(' ');
            string[] yparts = y.Split(' ');
    
            if (xparts[2] == yparts[2])
            {
                if (Convert.ToInt32(xparts[1]) > Convert.ToInt32(yparts[1]))
                {
                    return 1;
                }
                else if(Convert.ToInt32(xparts[1]) < Convert.ToInt32(yparts[1]))
                { 
                    return -1;
                }
                else
                {
                    return 0;
                }
            }
            else
            { 
            if (Convert.ToInt32(xparts[2]) > Convert.ToInt32(yparts[2]))
                {
                    return 1;
                }
                else if(Convert.ToInt32(xparts[2]) < Convert.ToInt32(yparts[2]))
                { 
                    return -1;
                }
                else
                {
                    return 0;
                }
            }
        }
    }
    

    And change last two lines in your example as below

    List<Series> sortedSeries =  series.OrderBy(i => i.Text, new SeriesTextComparer()).ToList();
    sortedSeries.ForEach(i => Console.WriteLine(i.Text));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Program { static void Main(string[] args) { var x = new Program(); Console.Write(x.Text);
class Program { static void Main(string[] args) { String value = Two; Type enumType
class Program { static void Main(string[] args) { List<Book> books = new List<Book> {
I have the following code: class Program { static void Main(string[] args) { new
class Program { static void Main(string[] args) { string value = "12345"; Type enumType
class Program { static void Main(string[] args) { MyDatabaseEntities entities = new MyDatabaseEntities(); var
Consider the following code: class Program { static void Main(string[] args) { new Program().Run(args);
class Program { static void Main(string[] args) { var dictionary = new Dictionary<string, int>()
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine(new
class Program { static void Main(string[] args) { List<A> myList = new List<A> {new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.