Using C Sharp: Part 3: Lists, Dictionaries, and Strings

C Sharp Basics:

Using C#

C# is a multi-paradigm programming language created by Microsoft as part of the .Net initiative in 2000. It has gone on to have its own standard and become part of everything from desktop applications to being used extensively in game development.


C# supports several different complex data types designed for different tasks. Three of the more data types are Lists, Dictionaries, and Strings from System.Collections.Generic.

Lists

The List is one of several generic data types available in C#. It is strongly-typed, which means the type of data stored in the structure is not only of the same type, but the type is declared when the object is created.

Lists have their own functionality through methods provided to Add(), Remove(), and Sort() items.

Dictionaries

Like List, a Dictionary is a strongly-typed generic date type where it contains a certain type and only that type. However, unlike List, it contains two data types: a key and a value.

In other programming languages, this structure is sometimes known as an associative array or table. In C#, it is a Dictionary.

Like List, it also has its own methods for handling entries: Add(), and Remove().

Dictionaries are not sorted or able to be sorted. To use a sorted Dictionary, the object SortedDictionary should be used.

Strings

While used throughout many example, String is its own special data type. As the documentation explains, it is a series of Char (character) entries. Because of this, it can be treated an an array of entries where data can be accessed through its index.

Play with the example on Repl.it!