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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:05:42+00:00 2026-06-05T13:05:42+00:00

I have the following City class. Each city object contains a dictionary which keys

  • 0

I have the following City class. Each city object contains a dictionary which keys are language tags (let’s say: “EN”, “DE”, “FR”…) and which values are the city names in the corresponding languages (ex: Rome / Rom etc.).

public class City:
{
  private IDictionary<string, string> localizedNames = new Dictionary<string, string>(0);
  public virtual IDictionary<string, string> Names
  {
    get { return localizedNames ; }
    set { localizedNames = value; }
  }
}

Most of the cities have the same names whatever the language so the City constructor does actually creates the English mapping:

  public City(string cityName)
  {
    this.LocalizedNames.Add("EN", cityName);
  }

Here comes the question: is there a way to add the other values via inline initialization?

I tried different variations of the following without semantic success (does not compile):

AllCities.Add(new City("Rome") { Names["DE"] = "Rom" };

I also tried creating a new Dictionary, but this obviously overwrites the “EN” parameter:

AllCities.Add(new City("Rome") { Names = new Dictionary<string, string>() { { "DE", "Rom" } } };

Anybody know if this is possible?

  • 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-05T13:05:45+00:00Added an answer on June 5, 2026 at 1:05 pm
    AllCities.Add(new City("Rome") { Names = { { "DE", "Rom" }, { "...", "..." } } });
    

    This is using initializer syntax to invoke the .Add method.

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

Sidebar

Related Questions

Let's say I have the following class: class Person { int age; String city;
Say you have the following object: public class Address { public String Line1 {
I have the following class called City that contains another class called Detail. public
Say I have got following two case class es: case class Address(street: String, city:
I have the following models: class City(models.Model): name = models.CharField(max_length=100) class Pizza(models.Model): name =
I have a file that contains the following in a csv file; country,region,city,postalCode,metroCode,areaCode I
I have got the following models, class City < ActiveRecord::Base belongs_to :state belongs_to :country
I have following classes. In instance of BE (let's say objBE) i want to
I have the following class: public class City { public string Name { get;
I have the following class: class Address { public string City {get; set;} public

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.