I have a few pages, each with a property named Data
. On another page I'm setting this data like this:
if (MyPage1 != null)
MyPage1.Data = this.data;
if (MyPage2 != null)
MyPage2.Data = this.data;
if (MyPage3 != null)
MyPage3.Data = this.data;
Is there any possibility to use the null-conditional operator on MyPage
? I'm thinking of something like this:
MyPage?.Data = this.data;
But when I write it like this, I get the following error:
The left-hand side of an assignment must be a variable, property or indexer.
I know it's because MyPage
could be null and the left-hand side wouldn't be a variable anymore.
It's not that I cannot use it like I have it already but I just want to know if there's any possibility to use the null-conditional operator on this.
SetData
method and doMyPage1?.SetData(this.data);
– Ladonna