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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:51:25+00:00 2026-05-10T22:51:25+00:00

I have a Dictionary that when I add multiple values to it, the items

  • 0

I have a Dictionary that when I add multiple values to it, the items that were entered before take the values of the item added. I am using the .Net 3.5 Here is the code:

public static Dictionary<string, Neighborhoods> Families()     {         if (File.Exists(calculatePath() + 'Family.txt')){}         else {File.Create(calculatePath() + 'Family.txt').Close();}         string[] inp = File.ReadAllLines(calculatePath() + 'Family.txt');         Neighborhoods temp = new Neighborhoods();         Dictionary<string, Neighborhoods> All_Families = new Dictionary<string, Neighborhoods>();         string currentphase = null;         foreach (string s in inp)         {             switch (s)             {                 case '!<Start Family>!': temp = new Neighborhoods();                     break;                 case '<Family Name>': currentphase = '<Family Name>';                     break;                 case '<End Family Name>': currentphase = null;                     break;                 case '<Neighbour Enabled>True': temp.Neighbourhood_Enabled1 = true;                     currentphase = '<Neighbour Enabled>True';                     break;                 case '<Neighbour Enabled>False': temp.Neighbourhood_Enabled1 = false;                     temp.Neighbourhood_Input1 = null;                     break;                 case '<University Enabled>True': temp.University_Enabled1 = true;                     currentphase = '<University Enabled>True';                     break;                 case '<University Enabled>False': temp.University_Enabled1 = false;                     temp.University_Input1 = null;                     currentphase = null;                     break;                 case '<Downtown Enabled>True': temp.Downtown_Enabled1 = true;                     currentphase = '<Downtown Enabled>True';                     break;                 case '<Downtown Enabled>False': temp.Downtown_Enabled1 = false;                     temp.Downtown_Input1 = null;                     currentphase = null;                     break;                 case '!<End Family>!': All_Families.Add(temp.Name, temp);                     break;                 default: if (currentphase == '<Family Name>') temp.Name = s;                     if (currentphase == '<Neighbour Enabled>True') temp.Neighbourhood_Input1 = s;                     if (currentphase == '<University Enabled>True') temp.University_Input1 = s;                     if (currentphase == '<Downtown Enabled>True') temp.Downtown_Input1 = s;                     break;             }         }         return All_Families;     } 

How can I make it so that when I add new keys and values, the old keys keep their original value


Sample data:

!<Start Family>! Family Name> qwe <End Family Name> <Neighbour Enabled>True qwe <University Enabled>True we <Downtown Enabled>True qwe !<End Family>! !<Start Family>! <Family Name> 123 <End Family Name> <Neighbour Enabled>True 123 <University Enabled>True 123 <Downtown Enabled>True 123 !<End Family>! 

Here is the nieghbourhoods class for reference. I will try the xml methods but it wont be finished quickly, I’m still learning this stuff.

class Neighborhoods {     public Neighborhoods()     {         name = '';         Neighbourhood_Enabled = false;         Neighbourhood_Input = '';         University_Enabled = false;         University_Input = '';         Downtown_Enabled = false;         Downtown_Input = '';     }      static string name;      public string Name     {         get { return Neighborhoods.name; }         set { Neighborhoods.name = value; }     }     static bool Neighbourhood_Enabled;      public bool Neighbourhood_Enabled1     {         get { return Neighborhoods.Neighbourhood_Enabled; }         set { Neighborhoods.Neighbourhood_Enabled = value; }     }     static string Neighbourhood_Input;      public string Neighbourhood_Input1     {         get { return Neighborhoods.Neighbourhood_Input; }         set { Neighborhoods.Neighbourhood_Input = value; }     }     static bool University_Enabled;      public bool University_Enabled1     {         get { return Neighborhoods.University_Enabled; }         set { Neighborhoods.University_Enabled = value; }     }     static string University_Input;      public string University_Input1     {         get { return Neighborhoods.University_Input; }         set { Neighborhoods.University_Input = value; }     }     static bool Downtown_Enabled;      public bool Downtown_Enabled1     {         get { return Neighborhoods.Downtown_Enabled; }         set { Neighborhoods.Downtown_Enabled = value; }     }     static string Downtown_Input;      public string Downtown_Input1     {         get { return Neighborhoods.Downtown_Input; }         set { Neighborhoods.Downtown_Input = value; }     } } 
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T22:51:25+00:00Added an answer on May 10, 2026 at 10:51 pm

    With the sample data you’ve given and the code you’ve given, it works okay using a Neighborhoods class like this:

    public class Neighborhoods {     public string Name { get; set; }     public string Neighbourhood_Input1 { get; set; }     public string University_Input1 { get; set; }     public string Downtown_Input1 { get; set; }     public bool Neighbourhood_Enabled1 { get; set; }     public bool University_Enabled1 { get; set; }     public bool Downtown_Enabled1 { get; set; } } 

    My test is to run this code:

    static void Main() {     var families = Families();      foreach (var family in x.Values)     {         Console.WriteLine(y.Name);     } } 

    That prints out ‘qwe’ and ‘123’ – showing that there are two different objects involved.

    However, we haven’t seen the real Neighborhoods class yet. I don’t suppose it’s using static fields (but still instance properties) is it? That would certainly explain the behaviour you’re seeing.

    EDIT: Yup, now you’ve shown us the Neighborhoods code it makes sense. Those fields are meant to be relevant for each instance, not just the type itself – so they shouldn’t be static.

    To show this is nothing to do with the parser, try this:

    Neighborhoods first = new Neighborhoods(); Neighborhoods second = new Neighborhoods();  first.Name = 'First'; Console.WriteLine(second.Name); 

    You’ll see it prints out ‘First’ – which is clearly not what you want!

    Unfortunately I don’t have a good page about what ‘static’ means, but I suggest you look it up in whatever C# books you have.

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

Sidebar

Related Questions

I have a dictionary that I want to add all the values to an
I have a Dictionary object that is formed using a double as its key.
I have a verses dictionary that contains these values: {cluster1: 0, cluster2: 0, cluster3:
I have a Google App Engine site, with multiple pages that are rendered using
I have a class that inherits from a dictionary in order to add some
I'm having trouble working through how to add an item to a dictionary that
I have a dictionary that has keys associated with lists. mydict = {'fruits': ['banana',
I have a dictionary that hosts diameter(in mm) and worth of euro coins: CoinsDiameters
Is it possible to clear a Flex flash.utils.Dictionary ? I have a Dictionary that
I'm newish to Python (and stackoverflow)...bear with me! I have a dictionary that looks

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.