Basics
Just some notes on basic C#, as I have recently been learning .NET
Architecture
Garbage Collection
Input / Output
void TestInput()
{
string formattingString = "Captured {0} input: {1}\n";
Console.Write("\nInput a character, then press enter: ");
int ascii = Console.Read();
char ch = Convert.ToChar(ascii);
Console.Write(formattingString, "character", ch);
Console.ReadLine(); // Discard any left over input
Console.Write("\nPress a key: ");
ConsoleKeyInfo key = Console.ReadKey();
Console.Write("\n" + formattingString, "key", key.KeyChar);
Console.Write("\nEnter a line: ");
string? line = Console.ReadLine();
Console.Write(formattingString, "line", line);
}
Value Types
Interfaces
void PrintEnum(IEnumerable<int> obj)
{
Console.WriteLine();
foreach (var i in obj)
{
Console.Write("{0}, ", i);
}
}
Generics
TODO: Differences from C++ templates
Generics are supported by class
, struct
, interface
, and delegate
types.
Nullable
Boxing
Class
Supports single inheritance, where a class may inherit from a single base class and extend or define functionality.
Classes may inherit from multiple interfaces, but may only inherit from a single base class.
Struct
Supports multiple inheritance, where N interfaces can inherit from each other to create a single interface