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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:16:37+00:00 2026-05-16T16:16:37+00:00

My dictionary declared as below public static Dictionary<object, DataInfo> DataDic = new Dictionary<object, DataInfo>();

  • 0

My dictionary declared as below

    public static Dictionary<object, DataInfo> DataDic = new Dictionary<object, DataInfo>(); 

    public class DataInfo
    {
        public string DSPER;       // Data Sample Period
        public int TOTSMP;      // Total Samples to be made
        public int REPGSZ;      // Report Group Size
        public List<int> IDList;   // Array List to collect all the enabled IDs
    }

Function InitDataDic Called below, How can I write the code of the dictionary .Remove() and .Add() after reassign tdi.TOTSMP = 0 under true condition in a simply way.

public void InitDataDic (object objid, DataInfo datainfo, int totsmp)
{
    DataInfo tdi = new DataInfo(); 
    object trid = objid;
    tdi = datainfo; 

    if (DataDic.ContainsKey(trid) == true)
    {
        DataDic.Remove(trid);  // here, i mentioned above
        tdi.TOTSMP = 0;
        DataDic.Add(trid, tdi);  // here, i mentioned above
    }
    else
    {
        tdi.TOTSMP = topsmp;  
        DataDic.Add(trid, tdi);
    }
}
  • 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-05-16T16:16:38+00:00Added an answer on May 16, 2026 at 4:16 pm

    You don’t have to add/remove from dictionary if you want to update the object (of ref type) in dictionary – just update the object.

    if (DataDic.TryGetValue(trid, out tdi)
    {
       // already exists in dict, tdi will be initialized with ref to object from dict
       tdi.TOTSMP = 0;   // update tdi
    }
    else
    {
      ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I declared a static mainDict like this, private static Dictionary<string, object> mainDict = new
If I declared a dictionary like this: private static Dictionary<string, object> aDict = new
I have a dictionary declared like this. public static Dictionary<int?, List<int?>> pegMap = new
I have code where this is declared: public IDictionary<string, OPTIONS> dict_Options = new Dictionary<string,
Suppose that I have a Dictionary<string, string> . The dictionary is declared as public
I declared the dictionary obj. Dictionary<string, string> aDict = new Dictionary<string, string>(); aDict .Add(IP,
Suppose that we declared the line below in our program : List<Dictionary<string, string>> list
I have declared a dictionary like this: Dictionary<string, KeyValuePair<string, string>> dc = new Dictionary<string,
I have a Dictionary that is declared thusly: Dictionary myDictionary<string, List<FCPort>> = new Dictionary<string,
As i know, the method to add values for dictionary as below. Dictionary<string, string>

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.