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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:35:09+00:00 2026-05-19T15:35:09+00:00

The situation is as follows: In a school where there is a certain class

  • 0

The situation is as follows:

In a school where there is a certain class that is divided into 2 groups:

The First is studying English and the other one German, however the time allocated for the classes is the same.

I have the virtual situation where in the IList (holding a record from the DB) I have the same Time class for the same class of Students and I need to join these objects using C# and preferably LINQ.

In other words, I need to merge one object into another when these objects have the same Time property. The final result will be displayed in the school schedule (timetable) and the problem is to avoid having duplicated records.

I currently have something like:

var lessons = KlassLesson.GetKlassSchedule(userProfile.Preferences.MyClassID, dayOfWeek);

lessons = JoinDoubleLessons(lessons);

private List<KlassLesson> JoinDoubleLessons(List<KlassLesson> lessons)
{
  // ?????
}
  • 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-19T15:35:09+00:00Added an answer on May 19, 2026 at 3:35 pm

    I should say that I’m not very clear about your question and since you’ve not answered my questions I’ve assumed that there is only one list and that this list contains some duplicate “AddedDate” values

    The following is completely functional code. I set up a few lessons. Note that I’ve assigned two of these lessons the AddedDate value from the variable “testDateAndTime”. The Lessons with Titles
    AAAAA
    and
    BBBBB

      class Program
      {
        static void Main(string[] args)
        {
          var testDateAndTime = DateTime.Now;
    
          var lessons = new Lesson[] {
            new Lesson { Title="A", Subject="English", AddedDate = DateTime.Now.AddMinutes(1)},
            new Lesson { Title="AA", Subject="English", AddedDate = DateTime.Now.AddDays(2)},
            new Lesson { Title="AAA", Subject="English", AddedDate = DateTime.Now.AddDays(3)},
            new Lesson { Title="AAAA", Subject="English", AddedDate = DateTime.Now.AddDays(4)},
            new Lesson { Title="AAAAA", Subject="English", AddedDate = testDateAndTime},
            new Lesson { Title="B", Subject="German", AddedDate = DateTime.Now.AddMinutes(5)},
            new Lesson { Title="BB", Subject="German", AddedDate = DateTime.Now.AddDays(6)},
            new Lesson { Title="BBB", Subject="German", AddedDate = DateTime.Now.AddDays(7)},
            new Lesson { Title="BBBB", Subject="German", AddedDate = DateTime.Now.AddDays(8)},
            new Lesson { Title="BBBBB", Subject="German", AddedDate = testDateAndTime}
          };
    
          var groupedLessons = from l in lessons
                               group l by l.AddedDate into g
                               select new { AddedDate = g.Key, Lessons = g };
    
          foreach (var k in groupedLessons)
          {
            Console.WriteLine("Added Date: " + k.AddedDate);
            foreach (var l in k.Lessons)
            {
              Console.WriteLine("\t Lesson Title: " + l.Title);
            }
          }
    
        }
      }
    
      public class Lesson
      {
        public string Title { get; set; }
        public string Subject { get; set; }
        public DateTime AddedDate { get; set; }
      }
    

    The output I get is:

    Added Date: 2/2/2011 3:25:36 AM
             Lesson Title: A
    Added Date: 2/4/2011 3:24:36 AM
             Lesson Title: AA
    Added Date: 2/5/2011 3:24:36 AM
             Lesson Title: AAA
    Added Date: 2/6/2011 3:24:36 AM
             Lesson Title: AAAA
    Added Date: 2/2/2011 3:24:36 AM
             Lesson Title: AAAAA
             Lesson Title: BBBBB
    Added Date: 2/2/2011 3:29:36 AM
             Lesson Title: B
    Added Date: 2/8/2011 3:24:36 AM
             Lesson Title: BB
    Added Date: 2/9/2011 3:24:36 AM
             Lesson Title: BBB
    Added Date: 2/10/2011 3:24:36 AM
             Lesson Title: BBBB
    

    Which shows two lessons (AAAAA and BBBBB) for the added date of 2/2/2011 3:24:36 AM
    which is what I expect. But then again, I’m not sure what you’re expecting. I’m not sure about what you mean by “merge”. What you have with this solution is that duplicates have been identified (and grouped) so you can now take the duplicates and “merge” them any way you see fit.

    You could modify the sql expression such that you get only the duplicates like so:

    var groupedLessons = from l in lessons
                         group l by l.AddedDate into g
                         where g.Count() > 1
                         select new { AddedDate = g.Key, Lessons = g };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My situation is a follows: There is some class MyList that will probably get
Essentially, the situation is as follows: I have a class template (using one template
Situation is as follows: There is a separate object that is responsible for generating
The situation is as follows: there's a website that connects sellers and buyers, like
My situation is as follows: I have a script file ( somescript.js ) that
The situation is as follows: I have a ViewModel that has a property that's
My situation is as follows: My class SettingsViewController is a subclass of UINavigationController .
Suppose I have a diamond inheritance situation as follows: class A{ public: virtual void
The situation is as follows. public interface IFoo { } public abstract class FooBase
The situation is as follows. Currently i'm developing an AIR game that will contain

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.