0

I swear I have seen this but cannot seem to remember where.

I have simple properties (with no custom backing variable) as follows:

public string CityName { get; set; }

When the property changes I want the OnPropertyChanged event to fire. I swear I have seen something like this

public long CityName {get; set { OnPropertyChanged(); } }

but I cannot seem to find any examples. Can you do what I am asking without having an independent backing variable? The difference in my question is I do not want to use a variable to hold the value of the property.

George M Ceaser Jr
  • 1,497
  • 3
  • 23
  • 52
  • May be this - [http://stackoverflow.com/questions/12034840/handling-onpropertychanged](http://stackoverflow.com/questions/12034840/handling-onpropertychanged) – kgzdev Jan 24 '17 at 20:07
  • You can't put code in the setter of an auto-implemented property. I wish you could, but you can't. [Try snippets](https://swissarmycrowbar.wordpress.com/2016/07/19/viewmodel-property-snippets-c6/). Won't save code, but it'll save typing and you can just collapse the `#region` and not have to look at it. – 15ee8f99-57ff-4f92-890c-b56153 Jan 24 '17 at 20:08
  • These example all appear to have backing variables – George M Ceaser Jr Jan 24 '17 at 20:14
  • Possible duplicate of [Simplest way to achieve automatic notification of property change](http://stackoverflow.com/questions/4716400/simplest-way-to-achieve-automatic-notification-of-property-change) – Eugene Podskal Jan 24 '17 at 20:16
  • No not a duplicate of the indicated question. They all have backing variables also. FYI in VB.Net you never need a backing variable for your property because one is automatically created for you by declaring the property. :) – George M Ceaser Jr Jan 24 '17 at 20:23

1 Answers1

0

So it appears this can't be done in C#.

George M Ceaser Jr
  • 1,497
  • 3
  • 23
  • 52