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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:19:55+00:00 2026-05-22T18:19:55+00:00

I have an object ( MyObj ) that itself will hold a List of

  • 0

I have an object (MyObj) that itself will hold a List of other objects of various types and I want to count them as they are added to MyObj. That’s the simple explanation, anyways…

I have an Interface (MyInterface) that all sub-objects agree to. MyObj has a List(Of MyInterface) property that all the sub-objects are added to. MyInterface will expose a property that lets me figure out what subtype each object is (the sub-objects do not inherit from MyObj at all).

But I want to count these sub-objects as they are added to the list, and I’m trying to find a good way to do it. I don’t need to worry about decrementing the count, as I am going to mimic the behavior of String and just create a new instance of MyObj if it ever changes, so all my counts will start from 0. This’ll hit the garbage collector a bit, but I think this will allow for simpler (and safer) code.

The only sane way I can think of to count objects is a very large structure in MyObj that uses bytes to hold the count (I will never have more than 255 of any given sub-object in the list in MyObj). But, even using bytes, this structure will be about 100-200 bytes big in memory (I have that many sub-objects), and I anticipate having a fair amount of MyObj copies running around, too.

I’ll also need a large Select Case to know which count property to increment when a new sub-object is added. This seems to be a bit ugly, though I’ve used this approach several times already.

What I am wondering is, instead of counting each object as it is added to the list, is there some way to query the list and count only the objects of a specific type? I wouldn’t need to store this anywhere, since it would be dynamic, like querying a database and asking for a count of a specific column or type of record.

I suspect Linq can do this, but Linq is also quite slow. Are there other approaches? Perhaps a predicate of some kind?

EDIT: I tink I want something like this in Linq, but I’m a bit confused on how to format it in VB (I am not a C# guy):

From i in MyObj.MyList Group i by i.GetType into g Let c as Int32 = g.Count()

And that’s it so far. I am still googling, but I am getting way too many C# and SQL references.

  • 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-22T18:19:56+00:00Added an answer on May 22, 2026 at 6:19 pm
    MyObj.MyList.OfType(Of Int32)().Count()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vector (order is important) of objects (lets call them myobj class)
Say I have a List of objects, and the object has a string property.
I have a class that holds some constants and will receive an object literal
I have an AS3 Object: {p1:.., p2:..} I want con create another object that
I javascript I have an object that looks similar to: var myObj = {
Say I have the following java code: Object myObj = new ArrayList(); List myList
Let's suppose I want to create a javascript class/object/function which have a method that
I have two tables: object that has object_id column and avalues that have object_id
I think I read somewhere that some modules only have object oriented interfaces (
I have an object that is mapped to a cookie as a serialized base-64

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.