Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C#, How to get the value of a variable when it changes Without threads or timers

Tags:

c#

int i = 0;

When i value changes:

i = (Atypical value)

then

bool callback(int i)
   target = i;
   return true;

In C#, How to get the value of a variable when it changes Without using threads or timers

like image 972
user8023045 Avatar asked May 17 '17 03:05

user8023045


People also ask

What is '~' in C language?

In mathematics, the tilde often represents approximation, especially when used in duplicate, and is sometimes called the "equivalency sign." In regular expressions, the tilde is used as an operator in pattern matching, and in C programming, it is used as a bitwise operator representing a unary negation (i.e., "bitwise ...

What is & operator in C?

&& This is the AND operator in C programming language. It performs logical conjunction of two expressions. ( If both expressions evaluate to True, then the result is True.

What does -= mean in C++?

-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand. C -= A is equivalent to C = C - A.


Video Answer


1 Answers

Use a property:

private int _i = 0;
public int i
{
    get { return _i; }
    set
    {
        if (_i == value) { return; }
        _i = value;
        callback(value);
    }
}
like image 138
Luke Joshua Park Avatar answered Oct 22 '22 06:10

Luke Joshua Park