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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:38:31+00:00 2026-05-19T23:38:31+00:00

i have a list of structs : user_stocks = new List<stock_Str>(); the struct is

  • 0

i have a list of structs : user_stocks = new List<stock_Str>();

the struct is defined:

public struct stock_Str
{
    public String name;
    public int quote ;
    public int chenge;
    public bool quote_a;
    public bool chenge_a;   
    public int[] rate_alarm;   
    public int[] chenge_alarm;
}

when i add item to the list i do:

stock_Str str = new stock_Str();
str.name = tbStockName.Text;
str.chenge_a = false;
str.quote_a = false;
str.quote = 0;
str.chenge = 0;
str.chenge_alarm = new int[2];
str.rate_alarm = new int[2];

for (int i = 0; i < 2; i++)
{
    str.rate_alarm[i] = 0;
    str.chenge_alarm[i] = 0;
}

_mainApp.user_stocks.Add(str);

my problems:

  1. when i try to change values of the list items(of type struct), it don’t change them!

  2. my two arrays of two int’s always set to null!

how can i fix it?

  • 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-19T23:38:32+00:00Added an answer on May 19, 2026 at 11:38 pm

    a: that should not be a struct, at all
    b: the “value” of a struct is never null; even Nullable<T>‘s null is a bit of a magic-trick with smoke, mirrors and misdirection

    Re the problem;

    1: yes, that is because structs have copy semantics; you have altered a copy – not the same one

    2: probably the same thing

    Here’s a more appropriate implementation; I imagine it’ll fix most of your problems:

    public class Stock
    {
        public string Name {get;set;}
        public int Quote {get;set;}
        public int Chenge {get;set;}
        public bool QuoteA {get;set;}
        public bool ChengeA {get;set;}
        public int[] RateAlarm {get;set;}
        public int[] ChengeAlarm {get;set;}
    }
    

    I’m unclear what the intent of the last 2 is, but personally I would prefer a list if it is a dynamic collection, for example:

        private List<int> rateAlarms;
        public List<int> RateAlarms {
            get { return rateAlarms ?? (rateAlarms = new List<int>()); }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an adjacency_list graph defined as follows: struct VertexProperties{ std::string name; ... };
I have a class class PCB { public: struct { string type; **linklist list;**//refer
I have a singly linked list with node and list structs defined as: typedef
I have a List where element is: struct element { double priority; int value;
I have a List of structs List<Student> studentList = new List<Student>() and I want
I have the following struct defined in a user control: public struct ColumnData {
I have a Linked List and I want to implement a function: Random_Shuffle_List (struct
I have the following problem: list.c struct nmlist_element_s { void *data; struct nmlist_element_s *next;
I have a struct called coordinate which is contained in a list in another
I have the following in my Struts ActionForm private List<FormFile> attachmentList = new ArrayList<FormFile>();

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.