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

  • Home
  • SEARCH
  • 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 69013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:30:24+00:00 2026-05-10T19:30:24+00:00

The title is kind of obscure. What I want to know is if this

  • 0

The title is kind of obscure. What I want to know is if this is possible:

string typeName = <read type name from somwhere>; Type myType = Type.GetType(typeName);  MyGenericClass<myType> myGenericClass = new MyGenericClass<myType>(); 

Obviously, MyGenericClass is described as:

public class MyGenericClass<T> 

Right now, the compiler complains that ‘The type or namespace ‘myType’ could not be found.’ There has got to be a way to do this.

  • 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. 2026-05-10T19:30:25+00:00Added an answer on May 10, 2026 at 7:30 pm

    You can’t do this without reflection. However, you can do it with reflection. Here’s a complete example:

    using System; using System.Reflection;  public class Generic<T> {     public Generic()     {         Console.WriteLine('T={0}', typeof(T));     } }  class Test {     static void Main()     {         string typeName = 'System.String';         Type typeArgument = Type.GetType(typeName);          Type genericClass = typeof(Generic<>);         // MakeGenericType is badly named         Type constructedClass = genericClass.MakeGenericType(typeArgument);          object created = Activator.CreateInstance(constructedClass);     } } 

    Note: if your generic class accepts multiple types, you must include the commas when you omit the type names, for example:

    Type genericClass = typeof(IReadOnlyDictionary<,>); Type constructedClass = genericClass.MakeGenericType(typeArgument1, typeArgument2); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 59k
  • Answers 59k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer If you're creating stuff and then passing it to be… May 11, 2026 at 9:02 am
  • added an answer In Script.aspx.cs, you can simply check the Request.Path in comparison… May 11, 2026 at 9:02 am
  • added an answer XMPP, previously known as Jabber, might be a good place… May 11, 2026 at 9:02 am

Related Questions

The title is kind of obscure. What I want to know is if this
The title is self explanatory. Is there a way of directly doing such kind
The title is pretty much self explanatory. Given two dates what is the best
Hopefully the title is self explanatory, what is the advantage of using the .call()
Sorry if the title is poorly descriptive, but I can't do better right now
Not sure if the title is quite right for the question but I can't
I'm not sure if the title is very clear, but basically what I have
The problem is in the title - IE is misbehaving and is saying that
As the title says: Is there a difference between $str == '' and strlen($str)
::GetSystemMetrics (SM_CYBORDER) ...comes back with 1 and I know the title bar is taller

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.