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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:16:23+00:00 2026-05-28T00:16:23+00:00

I have the below scenario List<Class> Classes = new List<Class>(); Class c1 = new

  • 0

I have the below scenario

List<Class> Classes = new List<Class>();
Class c1 = new Class() { ClassID = 1, Name = "Class1", Abbreviation = "CLS1" }; Classes.Add(c1);
Class c2 = new Class() { ClassID = 2, Name = "Class2", Abbreviation = "CLS2" }; Classes.Add(c2);
Class c3 = new Class() { ClassID = 3, Name = "Class3", Abbreviation = "CLS3" }; Classes.Add(c3);

List<ClassCode> ClassCodes = new List<ClassCode>();
ClassCode cc1 = new ClassCode() { ClassID = 1, ClassCodeID = 1, Code = "CC1", Description = "CCD1", Class = c1 }; ClassCodes.Add(cc1);
ClassCode cc2 = new ClassCode() { ClassID = 1, ClassCodeID = 2, Code = "CC2", Description = "CCD2", Class = c1 }; ClassCodes.Add(cc2);
ClassCode cc3 = new ClassCode() { ClassID = 2, ClassCodeID = 3, Code = "CC3", Description = "CCD3", Class = c2 }; ClassCodes.Add(cc3);
ClassCode cc4 = new ClassCode() { ClassID = 2, ClassCodeID = 4, Code = "CC4", Description = "CCD4", Class = c2 }; ClassCodes.Add(cc4);
ClassCode cc5 = new ClassCode() { ClassID = 3, ClassCodeID = 5, Code = "CC5", Description = "CCD5", Class = c3 }; ClassCodes.Add(cc5);
ClassCode cc6 = new ClassCode() { ClassID = 3, ClassCodeID = 6, Code = "CC6", Description = "CCD6", Class = c3 }; ClassCodes.Add(cc6);

I am trying to use Linq to transpose the above data in the below format

Class1   | CLS1    |    Class2   | CLS2   | Class3   | CLS3     - Columns
---------------------------------------------------------------------------
CCD1CCD2 |  CC1CC2 |   CCD3CCD4  | CC3CC4 | CCD5CCD6 | CC4CC5    - Row
  • Columns headers are values of Name (Class) and Abbreviation (Class) on the basis of group by on ClassID (ClassCode)
  • Value is concatination of Code (ClassCode) and Description (ClassCode) – Map is Code goes to Abbreviation Column and Description goes to Name Column
  • DataTable is a fit when you want to create properties at runtime – any other option will be appreciated.

    Please help!!

  • 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-28T00:16:24+00:00Added an answer on May 28, 2026 at 12:16 am

    You are not explaining why you are doing this.
    There might be other ways of achieving what you want.

    Anyway, the following code should work.
    It produces a DataTable, which I think is a good fit for this:

    var dt = new System.Data.DataTable("Transpose");           
    
    foreach (var c in Classes)
    {
        var dc1 = new System.Data.DataColumn(c.Name, typeof(string));
        var dc2 = new System.Data.DataColumn(c.Abbreviation, typeof(string));
        dc1.ExtendedProperties.Add("ID", c.ClassID);
        dc2.ExtendedProperties.Add("ID", c.ClassID);
        dt.Columns.AddRange(new System.Data.DataColumn[] { dc1, dc2 } );
    }
    
    var dr = dt.NewRow();
    
    for (int i = 0; i < dt.Columns.Count; i++)
    {
        var col = dt.Columns[i];
        dr[i++] = ClassCodes.Where(cc => cc.ClassID == (int)col.ExtendedProperties["ID"])
                            .Select(cc => cc.Description)
                            .Aggregate((first, next) => first + next);
        col = dt.Columns[i];
        dr[i] = ClassCodes.Where(cc => cc.ClassID == (int)col.ExtendedProperties["ID"])
                          .Select(cc => cc.Code)
                          .Aggregate((first, next) => first + next);
     }
    
     dt.Rows.Add(dr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all. Here is the scenario. I have the below code, and I'm needing
Okay so I have a scenario similar to the below code, I have a
I have below a list of text, it is from a popular online game
I have below code in html. <li class=selected runat=server id=lihome><a href=/ISS/home.aspx title=Home><span>Home</span></a></li> Now I
So imagine this scenario, I have a list and it has a bit of
I have the webform with dropdown list, label and textbox. Like below: <asp:DropDownList ID=ddlTest
Scenario: I have a generic list of Audits and a generic list of AuditImages.
I have the below scenario. We have MS access DB where system inserts the
Here's my scenario, I've got the following class, and I want to have the
I have a question regarding inheritance, so I will describe the scenario below: I

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.