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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:35:43+00:00 2026-05-27T03:35:43+00:00

Lets say I have an interface passed to my method: public void AlphaToChar(iList _blah)

  • 0

Lets say I have an interface passed to my method:

public void AlphaToChar(iList _blah)
{

}

Out of IList I want to extract it’s members Type and use its type to create other Arrays or Lists in the method. See example below.

The “List = new List();” part doesn’t work because, as I assume it’s a type variable, not the actual type.
Any way around this ? How can I accomplish this and create a new collection of an extracted Type?

Type[] listTypes =  list.GetType().GetGenericArguments();
Type listType = null;
if (listTypes.Length>0)
{
   listType = listTypes[0];
}
List<listType> = new List<listType>();

Thank you.

  • 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-27T03:35:43+00:00Added an answer on May 27, 2026 at 3:35 am

    You can do the List<> construction using the following:

    // Find the generic argument type of your old list (theList)
    Type genericType = theList.GetType().GetGenericArguments()[0];
    
    // Create a new List with the same generic type as the old one
    Type newListType = typeof(List<>).MakeGenericType(genericType);
    
    // Create a new instance of the list with the generic type
    var instance = Activator.CreateInstance(newListType);
    

    But it’s only going to work if you are using generic lists. The example you gave was using a regular IList. You would have to change your method signature to use a generic IList<>:

    public void AlphaToChar(IList<Something> _blah) { }
    

    Or make it even more generic:

    public void AlphaToChar<T>(IList<T> _blah) /* where T : ISomething, new() */ {}  
    

    Without doing so, you should know what your IList is going to contain and you wouldn’t have to use reflection to figure out what its elements types are.

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

Sidebar

Related Questions

So lets say I have this interface: public interface IBox { public void setSize(int
Lets say i have the following set of interfaces.... public interface IStart { void
Lets say we have this interface: public interface ILog { void Add(Message message); }
To keep things simplified lets say I have an interface RandomProvider interface public interface
Let's say I have a method public void Foo(string bar) that the caller should
Lets say we have a program which contains such classes: public interface AbstractItem {
Lets say I have some interfaces: public interface IFoo { IBar DoesStuff(); } public
Lets say I have this interface and class: interface IListener { void f(); void
Lets say I have a listener interface defined as: class Listener { public: virtual
Lets say I have a class, which implements a generic interface public interface IItem

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.