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 6121717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:48:57+00:00 2026-05-23T15:48:57+00:00

I have a class called Movies with the following variables declared: string Title; string

  • 0

I have a class called Movies with the following variables declared:

string Title;
string Plot;
string MPAA;
string Certification;
string[] Genres;

I create a List of Movies with the following code:

Movie m = new Movie(strTitle, strPlot, strMPAA, strCertification, strArrGenres);
MovieList.Add(m);

I’m now trying to figure out the best way to sort the list. I need to do two sorts, the first is a simple Sort by Title. I attempted to use LINQ, but I can’t figure out how to access the variable within the Movie correctly.

The second one will be more tricky. I need to sort by Genre THEN Title. Each movie of course can have multiple Genres, and I know I will end up with multiple movies since the movie will be in each Genre.

  • 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-23T15:48:58+00:00Added an answer on May 23, 2026 at 3:48 pm

    I did not understand how you want to sort by Genres if they are contained inside the movies, maybe you want to filter by genre and then sort by title?

        class Movie
        {
            public string Title { get; set; }
            public string[] Genres { get; set; }
        }
        static void Main(string[] args)
        {
            var movies = new List<Movie>();
            movies.Add(new Movie { Title = "Pulp Fiction", Genres = new string[] { "Crime", "Thriller" } });
            movies.Add(new Movie { Title = "Back to the Future", Genres = new string[] { "Adventure", "Sci-Fi" } });
            movies.Add(new Movie { Title = "The Dark Knight", Genres = new string[] { "Action", "Crime" } });
    
            var byTitle = from m in movies orderby m.Title select m;
    
            var crimeMovies = from m in movies where m.Genres.Contains("Crime") orderby m.Title select m;
        }
    

    EDIT: Selecting movies with genre and ordering by Genre then Title (as per comment):

            var distinctGenres = from m in movies
                                 from genre in m.Genres
                                 group genre by genre into genres
                                 select genres.First();                          
    
            var moviesWithGenre = from g in distinctGenres
                                  from m in movies
                                  where m.Genres.Contains(g)
                                  orderby g, m.Title
                                  select new { Genre = g, Movie = m };
    
            foreach (var m in moviesWithGenre)
            {
                Console.WriteLine("Genre: "+ m.Genre + " - " + m.Movie.Title);
            }
    

    Output:

    Genre: Action - The Dark Knight
    Genre: Adventure - Back to the Future
    Genre: Crime - Pulp Fiction
    Genre: Crime - The Dark Knight
    Genre: Sci-Fi - Back to the Future
    Genre: Thriller - Pulp Fiction
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called Movie with the following private data members: private: string
I have this class called Table: class Table { public string Name { get
I have a class called Book; class Book { public string Name { get;
I have Class called Person containing to properties, Father and List of Children. I
Inside of a class called Castle I have the following 2 functions: vector<Location> Castle::getMoves(Location***
I have a class called EventConsumer which defines an event EventConsumed and a method
I have a class called Ship and a class called Lifeboat Lifeboat inherits from
I have a class called DatabaseHelper that wraps a DbConnection. What's the proper way
I have a class called User with static function loginRequired(), which returns false if
i have this class called MemoryManager, it is supposed to implement a simple smart

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.