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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:39:19+00:00 2026-05-28T19:39:19+00:00

I have a List of Lists, with each list holding a different class of

  • 0

I have a List of Lists, with each list holding a different class of object. To add elements to the correct list, I need to be able to find the type of the list. I am currently trying to accomplish it in this way:

        foreach(object o in DataBase)
        {
            Type t = o.GetType();
            if (t != typeof(T))
                continue;
            else
            {
                List<T> L = (List<T>)o;
                L.Add(element);
                break;
            }
         }

However, this returns a List Type, of System.Collections.Generic.List`1[[myType,etc,etc]].
Is there a way to extract ‘myType’ from the type of List, for a proper comparison?

  • 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-28T19:39:20+00:00Added an answer on May 28, 2026 at 7:39 pm

    Use GetGenericArguments method:

    Type listTypeParam = myListType.GetGenericArguments()[0];
    

    Since myListType is an instance of a generic type with exactly one type parameter, the type T will be returned in the 0-th position of the returned array.

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

Sidebar

Related Questions

I have a list of lists that looks like this: x[[state]][[year]] . Each element
I have a nested list comprising ~30,000 sub-lists, each with three entries, e.g., nested_list
I have a list of objects and in each object they contain a list
I have one view holding a list of videos(buttons which can be clicked, each
I have a class holding entries in a list, which can be cleared and
I have a list of items & they are holding images, each image is
I have got a list holding customer information and each item of the customers
I have a List<T> that is holding several objects called tc of type TwitterCollection
I have a list of items. When I create the list each item has
I have an unordered list and each list element contains a photo and a

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.