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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:28:05+00:00 2026-06-08T16:28:05+00:00

Currently im facing the problem I need to create an instance of Dictionary with

  • 0

Currently im facing the problem I need to create an instance of Dictionary with any type of its cases. The types are delivered by the arguments of the method.
I do not simply want to create a dynamic or object type Dictionary, because this faces the user alot of convertion problems by using my library.
I also cannot use a simple constructor, because my method fills the Dictionary with data (that is stored in a file) in real. It’s important to create the specific dictionary by Type variables.
This is what im thinking of:

public static Dictionary<dynamic, dynamic> createDict(Type type1, Type type2)
{
    // how to create the dictionary?
    // im filling my dictionary with any data ...
    return dict;
}

Here the user calls my method:

Dictionary<string, int> dict = MyLib.createDict(typeof(string), typeof(int));
// or
MyOwnType myInstance = new MyOwnType();
Dictionary<string, MyOwnType> dict = MyLib.createDict(typeof(string), myInstance.GetType());
  • 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-08T16:28:14+00:00Added an answer on June 8, 2026 at 4:28 pm
    Type dictType = typeof(Dictionary<, >).MakeGenericType(Type1, Type2);
    var dict = Activator.CreateInstance(dictType);
    
    • Get the Type for Dictionary
    • Create a generic type with the specified Types using MakeGenericType
    • Create an instance of the generic type using Activator.CreateInstance
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently facing the problem that when i try to set focus on some
I'm currently facing new problem with operators. Using following code, I want to make
I'm currently facing a problem which I can not resolve and I really don't
I'm currently facing this problem with ruby on rails 3, devise and facebook oauth.
I'm currently facing a weird problem while executing a command from my bash script.
I'm developing android application with phonegap . Currently I'm facing one problem with inputbox
I am currently working on a Wordpress blog installation. Problem i am facing is
Currently I am facing a problem which I am unable to solve after a
I'm developing a Java/Spring web application. The problem I'm currently facing is that I'd
I'm creating an installer using Ant and I'm facing a problem. I need to

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.