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

  • Home
  • SEARCH
  • 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 7752177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:43:58+00:00 2026-06-01T11:43:58+00:00

I have List where myObj has it own list of objects called example mySubObj.

  • 0

I have List where myObj has it own list of objects called example mySubObj.
Object mySubObj has prop string Name.

So I want to create new List base on prop string Name from mySubObj.

I wrote this code, but it seems that it’s wrong:

var por = msgs.Where(x => x.Parameters
                        .Where(p => p.ParameterName == s).Count() == 1);

Can anyone help me with LINQ?

EDIT: This is whole code:

 foreach (string s in parameters)
            {
                using (StreamWriter streamWriter = new StreamWriter(outputFolder + "/" + s + ".xls"))
                {
                    streamWriter.Write("No.\tMessage\tMS\tTime\tSC");

                    var por = (from m in msgs
                               from p in m.Parameters
                               where p.ParameterName == s
                               select m).Distinct();


                    List<string> headeri = new List<string>();
                    List<string> vrijednosti = new List<string>();

                    foreach (L3Message p in por)
                    {
                        foreach (Parameter pam in p.Parameters)
                        {
                            TraverseForHeaders(pam, ref headeri);
                        }
                    }

                    foreach (string head in headeri)
                    {
                        streamWriter.Write("\t" + head);
                    }
                    streamWriter.Write("\n");

Edit 2:

Here is two of my classes, with this it should be more specified:

public class L3Message
{
    public int Number { get; set; }
    public string MessageName { get; set; }
    public string Device { get; set; }
    public string Time { get; set; }
    public string ScramblingCode { get; set; }

    public List<Parameter> Parameters { get; set; }

    public L3Message()
    {
        Parameters = new List<Parameter>();
    }}

public class Parameter
{
    public int numOfWhitespaces { get; set; }

    public string ParameterName { get; set; }
    public string ParameterValue { get; set; }

    public Parameter Parent { get; set; }
    public List<Parameter> SubParameters { get; set; }

    public Parameter()
    {
        SubParameters = new List<Parameter>();
    }


}
  • 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-06-01T11:43:59+00:00Added an answer on June 1, 2026 at 11:43 am

    How I understand it at the moment you want to create the “tree” with all parameters removed except the one you specified by name. You should create a copy of the Message for this, because if not you will change the original and cannot recover the “lost” parameters (I say this, because you said in the comments you want it to be temporary).

    So with this the code should be more or less like this:

            var por = (from m in messages
                       from p in m.Parameters
                       where p.ParameterName == s
                       select new L3Message { Number = m.Number, ...,  Parameters = new List<Parameter> { p } }
                      );
    

    Instead of “…” you have to copy the other parameters from message.

    All this being said, removing these properties temporarily seems like a bad solution to whatever problem you have. If you want to pass this to another method, can’t you change this method to tell it the property it should look at?

    Edit: Fixed code (second time)

    Edit2: Fixed code again (now duplicate properties result in additional messages, also see my alternative answer.

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

Sidebar

Related Questions

Say I have a List of objects, and the object has a string property.
I have two list containing List<MyObj>. and MyObj has a String ID member. I
I have list of video files in datagridview object, and I want to play
Say I have the following java code: Object myObj = new ArrayList(); List myList
I have a strongly typed list of custom objects, MyObject , which has a
I have list of transaction objects and want to order them by certain condition
I have list of objects(Artikel.java) and i add them to JComboBox. I want a
I have a List<MyObj> with the class MyObj : IComparable . I wrote the
I have List I want to sort Desc by Priority, which is int and
i have list of rows that user select and i want to delete them,

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.