Cheatography
https://cheatography.com
A cheat sheet to get an overview and small code examples for advanced C# concepts that could help your object oriented programming and encapsulation
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Classes
Classes are building blocks of software which encapsulate data and behavior.
Anatomy: Name, Fields, Methods
Declaration: AccessModifier + class + ClassName
Constructors: (code snippet: ctor)
- Constructors are methods that are called when an instance of a class is instantiated.
- Constructors have no return type.
- Constructors can be overloaded with different signatures.
public class ClassName() // default constructor
{ }
public class ClassName(int parameter) // overload
: this() //calls the default constructor
{}
|
Functions/Methods
- Methods are the functions of classes.
- Methods can be overloaded with different signatures.
Declaration: Access Parameter + Return Type + (Argument Type argument, ...) {}
Varying number of parameters:
public void MethodName(params int[] arguments) {}
Calling a function/method:
returnValue = FunctionName(arguments)
returnValue = ObjectName.MethodName(arguments)
|
|
|
Conventions
PascalCase |
classes, methods, properties |
camelCase |
method parameters |
_camelCase |
private fields |
Access Modifiers
|
accessible everywhere |
|
accessible only from inside the class |
|
|
|
Usable for classes, methods and variables.
Objects
var objectName = new ClassName();
|
Create an object |
|
Access public class methods |
var x = ObjectName.PropertyName()
|
Gets an object property. |
ObjectName.PropertyName = x
|
Sets an object property. |
|