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

  • Home
  • SEARCH
  • 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 6943671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:11:11+00:00 2026-05-27T13:11:11+00:00

A little background, this began in the question: Custom data type (Structures) vs arrays

  • 0

A little background, this began in the question: Custom data type (Structures) vs arrays.

I have managed to create struct State, and the List<State> to go along with it. Originally this was a multidimensional array, the purpose of which was for the 0-index to be an item in a combobox, and idexes 1-3 to then be displayed in 3 text boxes. My question now is, how do I duplicate this functionality by using the struct/List combination. The struct contains the same 4 fields as the original Array did, but I’m having problems understanding how to specify which field goes to which box. From what I’ve read elsewhere it should simply be a matter of using struct.field format, but it does’t seem to be working. As usual it’s probably something simple I’m missing, but I can’t seem to wrap my head around it.

On a side note, this list is meant to be completely immutable, none of this information is going to change/be changed (if it does, it will be at the code level and I’ll redo it myself, but user entry shouldn’t ever affect it).

Any help will be greatly appreciated.

Struct:

struct State
{
    private String StateID;
    private String TimeZone;
    private String CureType;
    private int CureTimeframe;

    public State(string stateID, string timeZone, string cureType, int cureTimeframe)
    {
        StateID = stateID;
        TimeZone = timeZone;
        CureType = cureType;
        CureTimeframe = cureTimeframe;
    }

    public override string ToString()
    {
        string data = String.Format("{0} {1} {2} {3}", StateID, TimeZone, CureType, CureTimeframe);
        return data;
    }
}

List<> initializer:

class StatesAndTerritories
{
    public List<State> stateData = new List<State>();
    public StatesAndTerritories ()
    {
        stateData.Add(new State("AL", "CST", "None", 0));
        stateData.Add(new State("AK", "AST", "COD", 10));
        stateData.Add(new State("AR", "CST", "COD", 10));
        stateData.Add(new State("AZ", "MST", "COD", 10));
        stateData.Add(new State("CA", "PST", "COD/Mandatory", 10));
        stateData.Add(new State("CO", "MST", "Mandatory", 20));
        stateData.Add(new State("CT", "EST", "Mandatory", 10));
        stateData.Add(new State("DC", "EST", "Mandatory", 10));
        stateData.Add(new State("DE", "EST", "None", 0));
        stateData.Add(new State("FL", "EST", "COD", 10));
        stateData.Add(new State("GA", "EST", "COD", 10));
        stateData.Add(new State("HI", "HST", "None", 0));
        stateData.Add(new State("IA", "CST", "Mandatory", 20));
        stateData.Add(new State("ID", "MST", "None", 0));
        stateData.Add(new State("IL", "CST", "COD", 10));
        stateData.Add(new State("IN", "EST", "None", 0)); 
        stateData.Add(new State("KS", "CST", "Mandatory", 20));
        stateData.Add(new State("KY", "EST", "None", 0));
        stateData.Add(new State("LA", "CST", "Replevin", 0));
        stateData.Add(new State("MA", "EST", "Mandatory", 21));
        stateData.Add(new State("MD", "EST", "Mandatory", 10));
        stateData.Add(new State("ME", "EST", "Mandatory", 19));
        stateData.Add(new State("MI", "EST", "COD/Mandatory", 30));
        stateData.Add(new State("MN", "CST", "COD", 10));
        stateData.Add(new State("MO", "CST", "Mandatory", 20));
        stateData.Add(new State("MS", "CST", "None", 0)); 
        stateData.Add(new State("MT", "MST", "COD", 10)); 
        stateData.Add(new State("NC", "EST", "None", 0));
        stateData.Add(new State("ND", "CST", "None", 0));
        stateData.Add(new State("NE", "CST", "Mandatory", 20));
        stateData.Add(new State("NH", "EST", "None", 0));
        stateData.Add(new State("NJ", "EST", "COD", 10)); 
        stateData.Add(new State("NM", "MST", "COD", 10));
        stateData.Add(new State("NV", "PST", "COD", 10));
        stateData.Add(new State("NY", "EST", "None", 0));
        stateData.Add(new State("OH", "EST", "COD", 10)); 
        stateData.Add(new State("OK", "CST", "COD", 10));
        stateData.Add(new State("OR", "PST", "COD", 10));
        stateData.Add(new State("PA", "EST", "None", 0));
        stateData.Add(new State("RI", "EST", "Mandatory", 24));
        stateData.Add(new State("SC", "EST", "Mandatory", 20));
        stateData.Add(new State("SD", "CST", "COD", 10));
        stateData.Add(new State("TN", "CST", "COD", 10));
        stateData.Add(new State("TX", "CST", "Mandatory",10));
        stateData.Add(new State("UT", "MST", "None", 0));
        stateData.Add(new State("VA", "EST", "None", 0));
        stateData.Add(new State("VT", "EST", "None", 0));
        stateData.Add(new State("WA", "PST", "COD", 10)); 
        stateData.Add(new State("WI", "CST", "Mandatory", 15));
        stateData.Add(new State("WV", "EST", "Mandatory", 10));
        stateData.Add(new State("WY", "MST", "None", 0));
    }

    public IEnumerable<State> GetStates (){
        return stateData;
    }
    public IEnumerable<State> GetStatesInTimeZone(string timezone)
    {
        return stateData;
    }
    public IEnumerable<State> GetStatesCureType(string curetype){
        return stateData;
    }
    public IEnumerable<State> GetStatesCureTimeframe(int curetimeframe){
        return stateData;
    }        
}

Combobox Population:

    public void PopulateStateInfo()
    {
        StatesAndTerritories states = new StatesAndTerritories();

        foreach (State state in states.stateData)
        {
            //string s = stateData[i, 0];
            stateInfoBox.Items.Add(states.stateData);
        }
    }

ComboBox Selection:

    private void stateInfoBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        StatesAndTerritories states = new StatesAndTerritories();
        try
        {
            stateTimeZone.Text = states.stateData.ToString();
            stateCureType.Text = states.stateData.ToString();
            stateCureTimeframe.Text = states.stateData.ToString();
            if (stateCureTimeframe.Text != 0.ToString())
            {
                stateCureAtDPD.Text = ((55 - int.Parse(stateCureTimeframe.Text)).ToString());
            }
        }
        catch (IndexOutOfRangeException)
        {
            stateTimeZone.Text = "";
            stateCureType.Text = "";
            stateCureTimeframe.Text = "";
            stateCureAtDPD.Text = "";
        }
    }
  • 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-27T13:11:12+00:00Added an answer on May 27, 2026 at 1:11 pm

    Firstly, you can not reach the content of the struct,

    private String cvStateID;
    private String cvTimeZone;
    private String cvCureType;
    private int cvCureTimeframe;
    

    These are private hence cannot be accessed from outside of the struct.
    You need to define public readonly properties for them:

    public readonly string StateID { get { return cvStateID; } }
    public readonly string TimeZone { get { return cvTimeZone; } }
    public readonly string CureType { get { return cvCureType; } }
    public readonly int CureTimeframe { get { return cvCureTimeframe; } }
    

    Next, I think you only want to display the StateID in the combobox. If so, you need to write the ToString() accordingly:

    public override string ToString()
    {
        return StateID.ToString();
    }
    

    In PopulateStateInfo method you are not adding each and every item in the list but adding the whole collection which is unusual! A proper implementation would be like:

    public void PopulateStateInfo()
    {
        StatesAndTerritories states = new StatesAndTerritories();
    
        foreach (State state in states.GetStates())
        {
            stateInfoBox.Items.Add(state);
        }
    }
    

    Lastly, a proper way of handling the SelectedIndexChanged event would be like:

    private void stateInfoBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        State selectedState = (State)stateInfoBox.SelectedItem;
        stateTimeZone.Text = selectedState.TimeZone;
        StateCureType.Text = selectedState.CureType;
        stateCureTimeframe.Text = selectedState.CureTimeframe.ToString();
    }
    

    One last point I would like to mension is, please do not make the stateData element of the StatesAndTerritories class public. You would benefit from it, if it is mutable only from inside of the class.

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

Sidebar

Related Questions

First I will give a little background info so this question isn't completely without
Before I begin my question a little background info. I have the WCF service
Edit: A little background on this. We have a module that accepts 6 different
First, a little background: I'm displaying a data set with 288 rows and 8
First, a little background. I have strings that resemble the following: ((Foo.Bar.StartsWith(A)) && (Foo.Bar.EndsWith(B)))
A little background: I'm using Spring and Hibernate to create a really simple domain/dao/service
Little background: this is an absolute beginner's website. I am a Film major haha
A little background on this error: The customer getting this error message in their
I was wondering if somebody has some insight on this issue. A little background
A little background: I'm a C# developer starting to mess with the iPhone (have

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.