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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:04:44+00:00 2026-06-04T13:04:44+00:00

Im currently designing a winforms app that needs to be able to output values

  • 0

Im currently designing a winforms app that needs to be able to output values of various properties in various classes to a serial/udp port.

I was wondering if there is an easy way to iterate over all of the instances of classes in this project at runtime, and then display to the user a select bunch (maybe by using attributes?) and their corresponding string value so they can output any combination of these values.

So, for (a simplified) example, say i have two classes:

public class ClassA
{
  public double Price{get;set;}
  public int Units{get;set}
  //other properties that I don't want visible to the user
}

public class ClassB
{
  public string Name{get;set;}
  public string Description{get;set;}
  //other properties not visible to the user
}

I will have many instances of these classes instantiated at runtime (and they may not necessarily be linked/referenced/related to each other).

e.g.

public ClassA Cars = new ClassA();
public ClassB Models = new ClassB();
public ClassA PCs = new ClassA();
//set properties of these instances
//etc.. more of these

I would like to gather all of these instances and show the corresponding fields to the user:

Cars.Price = "1000";
Cars.Units = "3";
Models.Name = "BMW";
Models.Description = "Luxury Car";
PCs.Price = "3000";
PCs.Units = "20";

Note that the values will be changing at runtime, and this will need to be updated when sending out data.
I was hoping someone could point me in the right direction here.

EDIT

Looks like this may not be viable.

Is there a way I can store a list of objects, where these objects point to my property/field so that i can retrieve its value? Of course assume that these class instances will be created only once, and I could register the class property/field in my output class. Then the output class can iterate over this list, retrieve the value of the object to which it points to, and then send the required data out?

e.g.

class OutputData
{
  Dictionary<string,object> OutputDataList = new Dictionary<string,object>();

  public void RegisterData(string displayName, ref object dataField)
  {
    OutputDataList.Add(displayName,dataField);
  }

  //iterate over OutputDataList and get the value of the property/field it points to
}
  • 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-04T13:04:46+00:00Added an answer on June 4, 2026 at 1:04 pm

    If all of these objects exist for the lifetime of the application and you just need to keep track of all of them you could do that in the constructor for each class, something like:

    public class Tracker
    {
      public static List<object> AllObjects = new List<object>();
    }
    
    public class ClassA
    {
       public ClassA()
       {
          Tracker.AllObjects.Add(this);
       }
       ...
    }
    

    That way you’d only need to modify the classes you want to track and the instances will get tracked in the overall list. For the problem of which fields to track you can either use reflection or you can store something more interesting in all objects, maybe a Func<List<string>> which returns all the values of interest.

    The add line would then be:

          Tracker.AllObjects.Add(() => 
              { 
                yield return "Name:" + this.Name; 
                yield return "Description:" + this.Description;
              });
    

    You can then do:

    var ouputLines = Tracker.AllObjects.SelectMany(o => o());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently designing a smart client app (WPF) which needs to operate in an
I'm currently designing a complex website that needs to support Undo and Notifications for
I am currently designing a class library that will provide data to a web
I'm currently designing a system that requires an admin to log in using a
I'm currently designing a website that would involve storing a long list of names
i am currently designing a ebook reader app as my project, i am having
I'm currently designing an assembly that will be used by third parties. One of
I'm currently designing an architecture for a web-based application that should also provide some
I am designing a WinForms CRUD like app for a large group of Nurses
We are currently designing a REST API that we want to publish in a

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.