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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:27:39+00:00 2026-06-08T17:27:39+00:00

In a project I’m working on, I use complicated Dictionary objects a lot. Often,

  • 0

In a project I’m working on, I use complicated Dictionary objects a lot. Often, there are a lot of declarations like:

var d1 = new Dictionary<string, Dictionary<int, List<string>>>();
var d2 = new Dictionary<Tuple<string, string>, List<object>>();

Between typecasts and passing parameters and what not, this gets annoying. What I’d like to do is something like this, using an imaginary keyword “typedel”:

typedel ListDict = Dictionary<string, Dictionary<int, List<string>>>();
typedel PolyDict = Dictionary<Tuple<string, string>, List<object>>();

var d1 = new ListDict();
var d2 = new PolyDict();

So that I do not need to type the long Dictionary declarations every time – so what I want is something like defining shorthand abbreviations for a type name. How can I do this in the simplest way (using the fewest lines of code)?

  • 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-08T17:27:40+00:00Added an answer on June 8, 2026 at 5:27 pm

    For a “typedef” that you want to use a lot, you can just create a class that derives from the appropriate base class, as in @Ed S’s answer:

    class MyData : Dictionary<string, Dictionary<int, List<string>>>
    {   
    }
    

    However, this is not the same as what most people consider a typedef: you are introducing a new type, which has implications for things like reflection, typeof, the is operator, etc. The distinction may or may not matter to you, but it is there.

    Within a single source file, however, you can use the second form of the using clause to do a real typedef:

    using ListDict = Dictionary<string, Dictionary<int, List<string>>>();
    using PolyDict = Dictionary<Tuple<string, string>, List<object>>();
    

    In either case, while using a “typedef” will definitely save you typing, don’t discount the benefits of seeing the types spelled out explicitly in your code. This is the same reason why articles such as this blog post recommend using List<Foo> over a custom FooCollection : List<Foo> — with the explicit generic version you know what type of collection it is any what methods it exposes.

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

Sidebar

Related Questions

The project that I am working on (Node.js) implies lots of operations with the
Project I'm working on uses jQuery. I have a series of Ajax calls being
project is written on php. There is timestamp field in mysql it updates automatically.
Project file here if you want to download: http://files.me.com/knyck2/918odc So I am working on
Current project is an Mvc4 application, I had Ioc working and recently it just
The project i am working at right now requires some declarative way of defining
My project demands and upgrade from groovy 1.7.2 to 1.8.x stable release, there are
A project I am working on only builds with maven-2.2: for earlier versions, the
Project#1 has some interfaces and classes that project#2 references. Now I want to use
Project Silk looks good for social networking applications where there are streams of frequently

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.