Tag Archives: initialization

Make an initializing constructor for a child class in C#

An initializing constructor is a constructor that takes parameters to make it easy to initialize an object’s properties. This example shows how to reuse a class’s initializing constructor for a child class. The following Person class has an initializing constructor. … Continue reading

Posted in classes, OOP | Tagged , , , , , , , , , , , , , , | Leave a comment

Initialize a Dictionary in C#

The post Initialize two-dimensional arrays in C# explains how to initialize a two-dimensional array. Even though a Dictionary is a more complicated data type, you can use a similar method to initialize one. Simply enclose each of the Dictionary‘s key/value … Continue reading

Posted in syntax | Tagged , , , , , , , | Leave a comment

Initialize arrays, lists, and class instances in C#

You can initialize objects that implement IEnumerable such as arrays and lists by specifying items inside brackets and separated by commas. For example, the following code initializes an array of strings. // Arrays implement IEnumerable so this syntax works. string[] … Continue reading

Posted in arrays, classes, lists, OOP | Tagged , , , , , , , , , , , , , | 4 Comments