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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:58:49+00:00 2026-05-30T07:58:49+00:00

In my program I have a Class Tracer: using System; using System.Collections.Generic; using System.Linq;

  • 0

In my program I have a Class Tracer:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace Tracepak_Heat_Loss_Program
    {
        class Tracer
        {
            public string family;
            public string model;
            public string type;
            public int output;
            public int voltage;
            public int maxMaintain;
            public int maxIntermittent;
            public string tRating;
            public string approvals;
            public string code;

            public Tracer(string f, string m, string t, int o, int v, int mM, int mI,string tR, string a, string c) 
            {            
                family = f;
                model = m;
                type = t;
                output = o;
                voltage = v;
                maxMaintain = mM;
                maxIntermittent = mI;
                tRating = tR;
                approvals = a;
                code = c;
            }
        }    
    }

In my main form i have created instances of several tracers:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;


    namespace Tracepak_Heat_Loss_Program
    {
        public partial class mainForm : Form
        {
            public mainForm()
            {
                InitializeComponent();
            }

            private void mainForm_Load(object sender, EventArgs e)
            {
            }


            Tracer J3 = new Tracer("Raychem BTV", "3BTV1-CT", "Self-Reg", 3, 120, 150, 185, "T6", "FM/CSA/ATEX", "J3");
            Tracer J5 = new Tracer("Raychem BTV", "5BTV1-CT", "Self-Reg", 5, 120, 150, 185, "T6", "FM/CSA/ATEX", "J5");
            Tracer J8 = new Tracer("Raychem BTV", "8BTV1-CT", "Self-Reg", 8, 120, 150, 185, "T6", "FM/CSA/ATEX", "J8");
            Tracer J10 = new Tracer("Raychem BTV", "10BTV1-CT", "Self-Reg", 10, 120, 150, 185, "T6", "FM/CSA/ATEX", "J10");

I have a method in my main form that returns the tracer name from a listbox

    public string GetTracer()
    {
        String s = tracerListBox.Text;
        int index = s.IndexOf(" ");
        return index >= 0 ? s.Substring(0, index): s;
    }
    // This could yield "J3" for example

I want to be able to use the results of GetTracer() to retrieve properties of that tracer.

For Example:

I could call

    J3.family;

    // The result of which is "Raychem BTV"

What I want to do is use

    GetTracer().family;

and have it return the property associated with the tracer that my method GetTracer returns.

Is this possible? Thank you in advance for your assistance. I am very new to programming and, while I am trying to make my code more robust by using classes, it is proving to be more difficult than I imagined.

  • 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-30T07:58:50+00:00Added an answer on May 30, 2026 at 7:58 am

    No need for local variables J3,J5,J8 etc. and other data structures.
    Just add a ToString method to your Tracer class

    public override string ToString()
    {
        return code;
    }
    

    and add your Tracer objects to listbox as below

    listBox.Items.Add( new Tracer("Raychem BTV", "3BTV1-CT", "Self-Reg", 3, 120, 150, 185, "T6", "FM/CSA/ATEX", "J3") );
    listBox.Items.Add( new Tracer("Raychem BTV", "5BTV1-CT", "Self-Reg", 5, 120, 150, 185, "T6", "FM/CSA/ATEX", "J5") );
    listBox.Items.Add( new Tracer("Raychem BTV", "8BTV1-CT", "Self-Reg", 8, 120, 150, 185, "T6", "FM/CSA/ATEX", "J8") );
    listBox.Items.Add( new Tracer("Raychem BTV", "10BTV1-CT", "Self-Reg", 10, 120, 150, 185, "T6", "FM/CSA/ATEX", "J10") );
    

    This way, you will see the codes in your ListBox.

    In some of ListBox’s event you can get the tracer object as

    void listBox_SelectedIndexChanged(object sender, EventArgs e)
    {
        Tracer tracer =  ((ListBox)sender).SelectedItem as Tracer;
        MessageBox.Show(tracer.family);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program which write logging as Text File. namespace logging { using
I am using boost shared pointers in my program, and I have a class
I have a program with a class that contains a public enum, as follows:
I have a program that looks something like this: public partial class It {
In my program I have multiple instances of a specific class Tracer (A1,B2,C3 etc).
I have a class called ModelView which inherits from NSOpenGLView. When my program runs
I have a program for a C class I need to write. The program
I have a main class in a program that launches another class that handles
I have a DAL class library that is included in my program as a
I have a program in which I need to store a Class object into

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.