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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:35:29+00:00 2026-06-10T06:35:29+00:00

I’m making a graphic control class Info which should display some text on screen.

  • 0

I’m making a graphic control class Info which should display some text on screen. The text is some object’s string. I’d like to be able to get that object’s latest value from within an instance of Info class.

class Info
{
    public string Text;
}

void Program()
{
    ClassA obj = new ClassA();
    obj.name = "Instance of ClassA";
    Info wind1 = new Info();
    wind1.Text = obj.name; // this just copies current value, but should be a reference or something 

    /* obj.name value changes several times before it's time to display it again */

    // Info window drawing method
    foreach (var item in Windows) // Windows is List<Info>
    Draw(item.Text); // this doesn't get the latest value
}

How should I change the code so I can get the latest string value from within the drawing section?

  • 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-10T06:35:30+00:00Added an answer on June 10, 2026 at 6:35 am

    Update: If you need something that’ll work for any type, you’ll have to use delegates. For example:

    class Info
    {
        private Func<string> getText;
    
        public Info(Func<string> getText)
        {
            getText = getText;
        }
    
        public string Text
        {
            get
            {
                return getText();
            }
        }
    }
    
    void Program
    {
        ClassA obj = new ClassA();
        obj.name = "Instance of ClassA";
        Info wind1 = new Info(() => obj.name);
    
        // Now do your stuff.
    }
    

    In this case, Info is given an anonymous function that returns a string. When you access its Text property, the function is evaluated to retrieve that string. How the string is retrieved, and where it comes from, is determined by the client code (i.e. the Program method). This way, Info doesn’t rely on any particular type.


    You could pass the ClassA object into your Info instance, so that it can get the value of.name itself.

    Something like this, perhaps?

    class Info
    {
        public Info(ClassA obj)
        {
            TheObject = obj;
        }
    
        public ClassA TheObject
        {
            get;
            set;
        }
    
        public string Text
        {
            get
            {
                return TheObject.name;
            }
        }
    }
    
    void Program
    {
        ClassA obj = new ClassA();
        obj.name = "Instance of ClassA";
        Info wind1 = new Info(obj);
    
        // Now do your stuff.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.