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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:32:42+00:00 2026-05-11T17:32:42+00:00

Does C# allow hashtables to be populated in one-line expressions? I am thinking of

  • 0

Does C# allow hashtables to be populated in one-line expressions? I am thinking of something equivalent to the below Python:

mydict = {"a": 23, "b": 45, "c": 67, "d": 89}

In other words, is there an alternative to setting each key-value pair in a separate expression?

  • 1 1 Answer
  • 2 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-11T17:32:43+00:00Added an answer on May 11, 2026 at 5:32 pm

    C# 3 has a language extension called collection initializers which allow you to initialize the values of a collection in one statement.

    Here is an example using a Dictionary<,>:

    using System;
    using System.Collections.Generic;
    
    class Program
    {
        static void Main()
        {
            var dict = new Dictionary<string, int>
            {
                {"a", 23}, {"b", 45}, {"c", 67}, {"d", 89}
            };
        }
    }
    

    This language extension is supported by the C# 3 compiler and any type that implements IEnumerable and has a public Add method.

    If you are interested I would suggest you read this question I asked here on StackOverflow as to why the C# team implemented this language extension in such a curious manner (once you read the excellent answers to the question you will see that it makes a lot of sense).

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

Sidebar

Related Questions

Facebook does not allow callbacks on ip addresses. So how does one test their
While ruby does allow modifying any class at any place in the code, I
IE does not allow writing to the innerHTML property of style or head elements.
C++ does not allow polymorphism for methods based on their return type. However, when
Problem: does not allow me to renderBinary . The method renderBinary(InputStream) in the type
Why does gcc allow extern declarations of type void? Is this an extension or
Firefox 3.5 does not allow creating java OBJECT tag with Javascript (document.write)? this technique
The organization policy does not allow normal users be assigned to Administrators group of
Our websites article backend does not allow access to anything above </head> which prevents
Apart from the fact that HashSet does not allow duplicate values, what is the

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.