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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:42:29+00:00 2026-06-09T17:42:29+00:00

I can easily use a string array without declaring it in advance using something

  • 0

I can easily use a string array without declaring it in advance using something like this:

new string[]{"MyString1","MyString2"} 

And use it as a method parameter without having to declare a variable for it in advance. However I can’t do this properly with Dictionary<string,string>.
I tried:

new Dictionary<string,string>(){"1","2"}

And

new Dictionary<string,string>().Add("1","2"):

None of above worked in terms of being compiled.

  • 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-09T17:42:31+00:00Added an answer on June 9, 2026 at 5:42 pm

    Do it this way

    new Dictionary<string,string>(){{"Key1","Value1"},{"Key2","Value2"}};
    

    Every Dictionary entry is a combination of a Key and a corresponding value. Hence first entry is {"Key1","Value1"} where Key is "Key1" and value is "Value1" and so and so forth.

    And use it as a method parameter without having to declare a variable for it in advance. However I can’t do this properly with Dictionary. I tried :

    new Dictionary<string,string>().Add("1","2"):
    

    This cannot be used for method parameter as Add method does not return anything. Its a void method.

    Food for thought: Your new string[]{"MyString1","MyString2"} is single dimensional array namely string[] whereas dictionary is like string[x][2] where x is length of dictionary. (string[x][2] is just for representation purpose. I know its illegal declaration)

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

Sidebar

Related Questions

In Bash I can easily do something like command1 && command2 || command3 which
Using scons I can easily set my include paths: env.Append( CPPPATH=['foo'] ) This passes
In C# I use a Queue collection. I can easily Enqueue or Dequeue. Okay,
I can easily ascend the class hierarchy in Ruby: String.ancestors # [String, Enumerable, Comparable,
We can easily alert anything in java script. Is it possible to get this
I know that I can use FOR EACH to easily accomplish my goal below,
Is there any way, to make something like: $elements_string = array() foreach ($something as
Possible Duplicate: Java - easily convert array to set Can someone help me with
public static MapFrom Map(this IDataReader idr, params string[] columns) { return new MapFrom {
I can easily check IP addresses programmatically, but is there any way to set

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.