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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:39:39+00:00 2026-05-20T07:39:39+00:00

This is what I have ID Value 1 Val1 1 Val2 3 Val3 3

  • 0

This is what I have

ID Value
1  Val1
1  Val2
3  Val3   
3  Val4
4  Val5

I need

ID Value
1  Val1, Val2
3  Val3, Val4
5  Val4

I am stuck at this point:

      var groups = Result.GroupBy(res => res.ID);      
      foreach (var group in groups)
      {                       
        foreach (var entry in group)
        {

        }
       }

How to get the result into a new anonymous type?

Note, I also need a concrete type that can be serialized as well.

EDIT: The final solution was like

[Serializable]   
public class KeyValueCSV 
{
    public decimal Key { get;set;}
    public string CSVValues { get;set;}
}

List<KeyValueCSV> kvCSVList = new List<KeyValueCSV>();
KeyValueCSV kvCSV;

          var groups = Result.GroupBy(res => res.ID);      
          foreach (var group in groups)
          {  kvCSV = new KeyValueCSV();  
            foreach (var entry in group)
            {
               kvCSV.id = entry.id;
               kv.CSVValues = enrty.Value + ", ";
            }
           kvCSVList.Add(kvCSV);
           }
  • 1 1 Answer
  • 2 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-20T07:39:39+00:00Added an answer on May 20, 2026 at 7:39 am

    Group has everything you need

    [Serializable]   
    public class KeyValueCSV 
    {
        public string Key { get;set;}
        public List<string> CSVValues { get;set;}
    }
    
     var groups = 
           Result.GroupBy(res => res.ID)
           .Select(x => new KeyValueCSV() { 
                Key=x.key, 
                CSVValues= string.Join(",", x.ToList()) 
               }
           );
    

    You could also do it:

    var groups = (
    from res in Result
    group r by res.ID
    into grouping
    
    select
       new  KeyValueCSV()
       {
         Key =  grouping.Key,
         CSVValues=  string.Join(",", grouping.ToList())
       }
    );
    

    **Let me know if I messed something up 😉 I have been in the world of python recently so I might have managed to mix up some sytax…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my example. <select name=mydropdownbox> <option value=val1>val1</option> <option value=val2>val2</option> <option value=val3>val3</option> <option value=val4>val4</option>
I have a select statement which will return me 5 values as val1,val3,val5,val2,val4 I
I have the following xml file. <a> <b> <c>val1</c> <d>val2</d> </b> <b> <c>val3</c> <d>val4</d>
I have strings like this: `(val1, val2, val3)` And I have ANTLR grammar to
I have a table like this: +-----+------------+-------+--------+-----------+ | ID | val1 | val2 |
I have DataTable object with next data: Id Value 1 val1 3 val2 2
I have one String variable, str with possible values, val1 , val2 and val3
Does setting this value have the same effect as setting the debug=true in the
I have this ticks value 634758517020305000 which corresponds to 21st June 2012. I tried
Using MATLAB, I have this code: value = input('>> Enter a value: '); and

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.