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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:12:22+00:00 2026-06-17T15:12:22+00:00

I’m doing the following request. It works as supposed to and returns data structured

  • 0

I’m doing the following request. It works as supposed to and returns data structured correctly. (It creates an element with “head” corresponding to the common field and puts the all elements of the same value in that field as a an Array in the “tail”.)

var result
  = from A in As
    group A by A.F into B
    select new 
    {
      F1 = B.Key,
      F2 = from A in As
           where A.F == B.Key
           select A
    };

Now I’d like to declare it’s type explicitly. I’ve checked in the debugger that my assumption on types is correct, however, when I try to declare that, it gives me conversion errors.

  1. Why?
  2. How can I declare the type explicitly?

I’ve tried different variant of declarations and as but failed.

IEnumerable<Tuple<String, IEnumerable<MyType>>> result 
  = from ...
    } as Tuple<String, MyType>;

I know it’s doable but I lack the experience to get it right. I’ve noticed that the following works. However, I’m not sure how to take it a step further, exchanging Object for the actual variable type.

IEnumerable<Object> result 
  = from ...
    } as Object;
  • 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-17T15:12:23+00:00Added an answer on June 17, 2026 at 3:12 pm

    Although you know that the object “insides” are the same, C# is statically typed and resolves types based on their metadata (name, namespace…), not on their members. You select an anonymous type, not a Tuple, so the type resolver cannot “agree” with it being used as a Tuple.

    If you hover over the var keyword in Visual Studio, it will tell you what type is it (because it must be known during compile time, unless it’s a dynamic). However due to the fact you are using anonymous type, you will not be able to write the type explicitly – it has no name in the C# source code.

    What you might do is either define the type elsewhere

    internal class MyObj
    {
        public MyObj(string head, IEnumerable<Foo> tail)
        {
            Head = head;
            Tail = tail;
        }
    
        public string Head { get; set; }
        public IEnumerable<Foo> Tail { get; set; }
    }
    

    and then use it in your query:

    IEnumerable<MyObj> result
      = from A in As
        group A by A.F into B
        select new MyObj(
            B.Key,
            from A in As
            where A.F == B.Key
            select A);
    

    or use a Tuple as Jon suggested here.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I want to construct a data frame in an Rcpp function, but when I
I have a view passing on information from a database: def serve_article(request, id): served_article
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.