So, in some C# code, I have something similar to the two properties:
private string _foo;
private string _bar;
public Foo
{
get;
set {
_foo = value;
Bar = _foo.Substring(3, 5);
}
}
public Bar
{
get;
set {
_bar = value;
Foo = "XXX" + _bar;
}
}
Question: Are C# properties subject to circular references/updates, like this example would seem to cause?
You can avoid the infinite loop by updating the hidden field directly, like this:
This will bypass the other property’s setter, which eliminates the loop.
But… this generally causes maintenance headaches later on. Personally, I’d try to find an alternative design.