Search code examples
c#.netstack-overflow

How to make a property set itself using {} instead of ;?


Here is an interesting tidbit where I could not really find on the interwebs. The idea is that if you have a property such as int a { get; set; } it could set itself.

How do you make the property set itself with int a { get { } set { } }?

What is happening inside of set;?

Here is what I tried to do:

public string Symbol { get { return Symbol; } set { Symbol = value; NotifyPropertyChangedEvent("Symbol");  } }

But it obviously creates a Stack Overflow because it is essentially calling itself over and over.

And I don't want to create 10-20 private variables to work along side of my properties, I want to know what is happening in set;.

Thank you.


Solution

  • set; just creates a private variable that you can't see. You'll need those 10-20 private variables, sorry.