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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:46:57+00:00 2026-06-02T21:46:57+00:00

in C# using linq i have a query like: var result = from p

  • 0

in C# using linq i have a query like:

var result = from p in cart select new { p.Product.Title, p.Product.Price };

now i want to add some another items to result. For example adding:

int weight;
string message;

so that i can have something like:

foreach( var r in result)
{
   dosomething(r.weight;)
   dosomething(r.message);
   dosomething(r.title);
   dosomething(r.price);
  }

is it possible? how should i do it?

  • 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-02T21:46:59+00:00Added an answer on June 2, 2026 at 9:46 pm

    You can’t do that. Anonymous types are normal types and they are fixed at compile time. You can’t change them later.

    EDIT:
    You can create a container class for your result set and then select based on that:
    class MyResult

    class MyResult
    {
        public string Title { get; set; }
        public double Price { get; set; }
        public double Weight { get; set; }
        public string Message { get; set; }
    }
    

    And then you can use:

        var query = from t in cart
                    select new MyResult
                    {
                        Title = t.ProductTitle,
                        Price = t.Product.Price
                    };
    

    Later you could do:

    foreach( var r in result)
    {
       dosomething(r.Wight;)
       dosomething(r.Message);
       dosomething(r.Title);
       dosomething(r.Price);
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have linq query as follows: var result = (from Customer cust in db
I have a LINQ query: var result = from mt in MessageTypes join mtfmt
I am using LINQ to EF and have the following LINQ query: var results
I have a linq query that returns a list and the result looks like
I have a 'var' that contains results from two tables using LINQ to SQL.
I have a collection of MyClass that I'd like to query using LINQ to
I have been using LINQ with compiled queries, basically passing into the compiled query
I query my NHibernate datasources using a Linq Expression. The problem I have with
Using EF4 and Linq I have a data structure which looks like this: parentid
I'm using LINQ to SQL to query my database, I have a query very

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.