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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:41:28+00:00 2026-06-07T01:41:28+00:00

Ok.. I have a really awkward problem that I believe is related with how

  • 0

Ok.. I have a really awkward problem that I believe is related with how C# handles value types vs reference types but I’m just not sure what exactly the bug is.

public partial class LogicSimulationViewerForm : Form
    {

    private Dictionary<string, PointStruct> pointValues;


private void SearchPoint(string code)
    {
        ReadDefaultPointValuesResponse result = ddcdao.ReadDefaultPoint(points);
        pointValues = new Dictionary<string, PointStruct>();

        for (int j = 0; j < result.pointidentifier.Length; j++)
        {
            if (!pointValues.ContainsKey(result.pointidentifier[j]))
            {
                PointStruct ps = new PointStruct();
                ps.name = "Random String"; 
                ps.pointidentifier = result.pointidentifier[j];
                ps.outofservice = result.outofservice[j];

                pointValues.Add(result.pointidentifier[j], ps);
                ...

pointValues is stored as a private field in a class. Now in the same class but in a different function, if I try to do the following:

PointStruct ps = pointValues[s];
MessageBox.Show(ps.name);
MessageBox.Show(ps.pointidentifier);
MessageBox.Show(ps.outofservice);

The ps.pointidentifier and ps.outofservice is displayed correctly but ps.name is always returned as null no matter what I do. How can I fix this issue?

Edit: Upon request, I am adding more code to further illustrate the problem:

public struct PointStruct
{
    public string pointidentifier;
    public string affect;
    public string outofservice;
    public string priorityarray;
    public string pointtype;
    public string alarmstate;
    public string correctvalue;
    public string presentvalue;
    public string name;
    public string test;
}
  • 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-07T01:41:29+00:00Added an answer on June 7, 2026 at 1:41 am

    As long as there is no voodoo (explicit field layouts, property indirection, etc), there is absolutely no reason why a field should wipe itself, regardless of whether it is a class or a struct.

    If it was a class, we could perhaps put that down to a careless update somewhere else, i.e.

    var foo = pointValues[key];
    // snip 2000 lines
    foo.name = newValue; // which happens to be null
    

    which would of course update the same fundamental object as the one referenced by the dictionary. But that doesn’t apply to a struct, since the copies are separate (unless updating directly in an array).

    The only way I can see of causing that, given that you state that pointValues.Add(...) is only used in one place, is that you are overwriting it elsewhere via the indexer:

    pointValues[key] = newValueWithANullName;
    

    All that said, though; unless you have some very specific reasons, there is very little purpose for PointStruct to be a struct. That looks to me like it should be a class. It is very “fat” for a struct. Also; in most cases, structs should be immutable.

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

Sidebar

Related Questions

i have an awkward problem where calling to [self invalidateModel]; does not redraw my
I'm using Filemaker Pro 12 Advanced. I have a few tables but have really
I really have problem with this one. So I have a jar with a
I really have no idea what I did to cause this exception, but I
I have a very strange problem,I don't know whether it is awkward to normal
I've been struggling with something at work that I'm not really in the mood
this seems really awkward ...does anybody have any suggestions for a cleaner approach? bool
The title of this is kind of awkward; I wasn't really sure how to
I have really simple XML (HTML) parsing ANTLR grammar: wiki: ggg+; ggg: tag |
I have really basic question. How can I get form id by input element

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.