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

The Archive Base Latest Questions

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

I have a immutable List. In the below g.Select(…) I do a .ToList() which

  • 0

I have a immutable List.

In the below g.Select(…) I do a .ToList() which is put into the MemberIdList. I do not want to create a new List with ToList() rather I want to add each r.Field string to the immutable List inside the unit object.

How can I do this?

var groupedCollection = table.AsEnumerable()
        .GroupBy(row => new
        {
            UType = row.Field<string>("UnitType"),
            UZoom = row.Field<string>("UnitZoom"),
            MZoom = row.Field<string>("MemberZoom"),
        });

    var unitCollection = groupedCollection
        .Select(g => new Unit
        {
            UnitType = g.Key.UType,
            UnitZoom = g.Key.UZoom,
            MemberZoom = g.Key.MZoom,
            MemberIdList = g.Select(r => r.Field<string>("TestId")).ToList(),
        });

    List<Unit> units = unitCollection.ToList();


public class Unit
{
    public Unit()
    {
        MemberIdList = new List<String>();
    }

    public String UnitType { get; set; }
    public String UnitZoom { get; set; }
    public String MemberZoom { get; set; }
    public int MemberOrder { get; set; }

    public List<String> MemberIdList { get; private set; }
}
  • 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-23T01:28:55+00:00Added an answer on May 23, 2026 at 1:28 am

    Why not just create a constructor for Unit that takes the data for MemberIdList like:

    public Unit(IEnumerable<string> memberIdList)
    {
        MemberIdList = new List<string>(memberIdList);
    }
    

    and modify your select to:

    .Select(g => new Unit(g.Select(r => r.Field<string>("TestId")))
    {
        UnitType = g.Key.UType,
        UnitZoom = g.Key.UZoom,
        MemberZoom = g.Key.MZoom
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have import scala.collection.immutable.TreeMap val tree = new TreeMap[String, List[String]] Now after above
I have a property list which I read into an NSDictionary, from which I
I want to have immutable Java objects like this (strongly simplified): class Immutable {
I have a class which is intended for immutable use, hence I would like
If you have an immutable list, you expect it to always return a reference
More particularly, I really want an immutable/shared linked list, and I think having immutable
I have a list like: List<String> test = new List<String> {Luke, Leia}; I would
I have heard and read that a string can not be changed (immutable?). That
For the site I'm currently working on, I have a list of products which
I have a list, which may contain elements that will compare as equal. 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.