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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:39:50+00:00 2026-06-13T14:39:50+00:00

I need a place in my code where variables auto-update when other variables change

  • 0

I need a place in my code where variables auto-update when other variables change that they are dependent on.

The difference from spreadsheets is I don’t want all the parsing stuff, I just want everything done in code as I don’t need to update formulas/variables after the program has been compiled.

Basically there is input data, and a few “cells” from the spreadsheet part will listen in on those values, change, and the change will propagate through the “spreadsheet” part. Like a normal spreadsheet.

So I can then immediately after depend on all those values, instead of having to write all kinds of code to update all the variables correctly first, which would be very hard to do.

If anyone can help me with the thought process to implement this it would really help! I’ve been reading some spreadsheet source code but it will take a long time to understand that, and then understand how I would change those ideas to fit what I need to do.

Edit:
Right now I just have things in loops and structure everything correctly so it updates correctly like so:

A1 = 2;
B1 = A1 + 2;

Then this just loops again and again. But if I wanted things to update automatically, how would I store the calculations attached to the variables? So when updating B it would call A1 + 2 ?

By the way A1, and B1 are just random variables. I don’t name things by cell names and there is no such structure.

  • 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-13T14:39:51+00:00Added an answer on June 13, 2026 at 2:39 pm

    One way of storing calculations is to use the elements of functional programming that have been built into C#.

    A formula can be stored as a function, using one of the Func<T1,T2,...TResult> delegates.

    var CalculationForX = new Func<double, double, double>( 
        (arg1, arg2) => arg1 * arg2
    );
    

    Here, CalculationForX specifies a function that takes two doubles, and returns a the product of the two doubles. Then using for example CalculationForX(5, 2) returns 10.


    So, a straightforward way to keep track of all the dependencies would be to store an object for each dependent variable, containing its formula and inputs. These could be in the form of:

    • an array of strings that contain the property names of a given object
    • a PropertyInfo array
    • an Action<T1,T2> delegate represents the actual property setter

    Whenever you receive a property changed event, retrieve the calculation and the inputs for all variables that depend on it, and update the target values.

    (It’s funny to me that you asked this question, as I asked a quite similar one yesterday on Programmers.)

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

Sidebar

Related Questions

I need to concatenate two string variables and place the result back in the
I need to append a lot of HTML code. To improve readability, I don't
I need to place two repeated background images on the left and right border
I need to place the label text to left and the radio button to
I need to place default text to all rows for particular column in jquery
We need to place text over objects in a web page, similar to this:
I need to place several DatePicker widgets into the row. If there is not
I have this need to place my app in the share/send context menu so
I have created a Mac app and need to place a shadow behind the
I just wanted to know if I need to place a check for null

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.