Jump to content

Houndsteeth

Member
  • Posts

    1
  • Joined

  • Last visited

Awards

This user doesn't have any awards

Houndsteeth's Achievements

  1. Actually, the shorthand: public string Name { get; set; } (rightly) prevents you from accessing the backing fields. You would use the longhand version if you wanted to enforce validation or set values in other properties. A good example of how this is commonly used is for serialization. If you have a date value that is coming in from a data source via serialization (i.e., Xml or JSON), you can capture the string value from the serialization and do the type conversion in the object on the fly in another property, like so: private string _receivedOn; [XmlIgnore] public DateTime? ReceivedOn { get => DateTime.TryParse(_receivedOn, out DateTime dt) ? dt : (DateTime?)null; } [XmlAttribute("ReceivedOn")] public string ReceivedOnVal { get => _receivedOn; set => _receivedOn = value; }
×