C# – Call a constructor from another constructor

To call one constructor from another one, you have to use the constructor chaining syntax, like this: This means when you use the Person(string name) constructor, it’ll first call the Person(string name, string birthDate) constructor. If the constructor is in a base class, use base() instead of this(): Employee subclasses Person. So calling base(name) here … Read more

C# – Parsing a DateTime from a string

You can convert a string to a DateTime (parse) with one of these methods: I’ll show examples of using both methods for parsing various DateTime formats. Using DateTime.Parse() DateTime.Parse() can handle parsing a wide variety of culture-specific standard DateTime formats and the ISO-8601 format (which is the default date format for JSON serialization). By default, … Read more