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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:10:47+00:00 2026-06-16T03:10:47+00:00

I have the following class created: Public Class Candidate Public Account As String Public

  • 0

I have the following class created:

Public Class Candidate
    Public Account As String
    Public StartDate As Date
    Public EndDate As Date
End Class

Now, in a second class, I want to take a List(Of Candidate) and group it by matching start and end dates. I have the following code:

Public Class MyClass

Private _Candidates As New List(Of Candidate)
Private _Grouped_Candidates as ????????

    Sub Group_Candidiates()
        _Grouped_Candidates = From Candidate In _Candidates
            Group Candidate By StrtDt = Candidate.StartDate, EndDt = Candidate.EndDate Into Group
            Select New With {.Grp = Group, .StrtDt = StrtDt, .EndDt = EndDt}
    End Sub

End Class

And then at a different part of this class, I want to perform an operation on this in-memory query:

Sub DoStuff()
    For Each Grp In _Grouped_Candidates
        DoSometihng(Grp.Grp.Select(Function(Candidate) Candidate.Account).ToList, _
                                   Grp.StrtDt, _
                                   Grp.EndDt)
    Next
End Sub

This is giving me an error because I don’t have _Grouped_Candidates declared correctly.

My question is if this is bad programming practice (Keeping an in-memory query saved beyond the scope of a sub) and, if so, what should be done instead.
And, if not, how can I declare the query correctly so I can use it throughout my class?

Thanks!!!

  • 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-16T03:10:48+00:00Added an answer on June 16, 2026 at 3:10 am

    Anonymous types were designed specifically to be used within the scope of a single method. While there are means of using them across methods, they’re messy, generally bad practice, and on the whole much more work than they’re worth. The easiest solution is to create a new named type that has properties representing what your current anonymous type uses, and to then use that named type. Whoever is responsible for maintaining the code will thank you for putting in the tiny up-front time instead of using messy hacks.

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

Sidebar

Related Questions

I have the following class: public class DocketType : Enumeration<DocketType, int, string> { public
I have the following class Person: public class Person { public string Name {
I have the following class: public class Topic { public string Topic { get;
I have the following classes created: [Serializable] public class AppContext : IXmlSerializable { public
I have the following classes class A{ private String name; private int value; public
I have the following classes: public class Note { public string Text { get;
I have the following class: public class Content { public string PartitionKey { get;
I have created following class: public static class Current { public static class User
I have the following class: public class Data { static public SqlDataReader ExecutSql(string sql)
I have the following code: public class Page { public string FilePath { get;

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.