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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:28:29+00:00 2026-06-15T13:28:29+00:00

I want to go through a switch statement to determine what type to make

  • 0

I want to go through a switch statement to determine what type to make something that contains a generic with.

Below is a silly, but illustrative bit of code that shows what I am trying to do:

Type tempType;
switch(number)
{
   case 0:
      tempType = typeof(int);
      break;
   case 1:
      tempType = typeof(bool);
      break;
   case 2:
      tempType = typeof(long);
      break;
}

List<tempType> theList = new List<tempType>();

When I try this it gives the error:

The type or namespace name ‘tempType’ could not be found (are you missing a using directive or an assembly reference?)

My assumption on why is because it is looking for types that are globally available there, and is not looking in the local member variables of this method. How can I do something like this?

EDIT:
To give a bit more context, I am trying to use Quartz.NET, and I am trying to create different jobs with it, so each of the types in this example are different Job Classes, each with their specific execute commands. the different cases are when I want to access that specific job class. Then I would create the job via:

tempJob = JobBuilder.Create<tempType>()
            .WithIdentity("SomeJob " + i)
            .UsingJobData()
            .Build();
  • 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-15T13:28:30+00:00Added an answer on June 15, 2026 at 1:28 pm

    To use generics the compiler has to know the type at compile-time; you can not determine the type at runtime and create a generic. If you don’t know the type until runtime, you would generally just use a List.

    You could use reflection to create a particular type instantiation at runtime, but instantiating to a particular type is primarily useful to the compiler for type inference; if the compiler doesn’t know, there’s not a lot of reason for your program to care at runtime.

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

Sidebar

Related Questions

I'm trying to make a very simple toggle switch and I want to store
I have recently learned that you can use a neat switch statement with fallthrough
I want to search through a html file and then get the url to
I want to loop through the checkboxgroup 'locationthemes' and build a string with all
I want to loop through the controls on a UserControl and set a property
I want to iterate through a table/view and then kick off some process (e.g.
I want to go through each character in a String and pass each character
I want to go through the children of an element and filter only the
I want to pass through configuration arguments to a class. These are all the
I want to loop through a database of documents and calculate a pairwise comparison

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.