about
CSharpBits
9/09/2022
C# Bits
organized bits of syntax, idoms, and patterns
Quick Status
C# code bits | ||
---|---|---|
What is this? | Code demo | Commentary |
Hello World
The traditional first look at a new language |
|
C# functions are all methods of a class. They may begin with an access qualifier, a return type, accept
arguments in a parentisized list, and encapsulate
an executable code body in a set of statements enclosed in braces.
|
Hello Objects
Demonstrates how Types are defined and instances created. The type DemoObj is defined above its main function and instances dob and cln are created in main. |
|
Types are defined with classes, like DemoObj on the left. Functionality is provided through methods,
e.g., functions associated with the class. All methods are declared and defined in the body of a class declaration.
The function DemoObj::DemoObj(String name) creates an instance of DemoObj and endows it with a name.
Function DemoObj::name() implicitly accepts a reference to its instance and returns its name.
Static functions do not take a reference to self and so cannot access member data. They act like ordinary functions
but are accessed with their type followed by colons followed by the function. Non-static functions take an implicit reference
to self, can access member data, and are accessed from an object name followed by a period.
Types and functions declare public accessibility with the public keyword. Functions declare return types with
a type name prefix.
The code at the left declares the type and operations for DemoObj.
|
Hello Data | ||
Iteration | ||
Data Structures | ||
Functions | ||
Generic functions | ||
Structs | ||
Generic structs | ||
Basic DIP | ||
Generic DIP |