C# Cheat Sheet
by laurence via cheatography.com/42043/cs/12684/
Data Types Type Conversion Methods (cont)
bool Boolean value ToUInt64
byte 8-bit unsigned integer
Naming Conventions
char 16-bit Unicode character
decimal 128-bit precise decimal values with 28-29 significant digits Class MyClass
double 64-bit double-precision floating point Method MyMethod
float 32-bit single-precision floating point Local variable myLocalVariable
int 32-bit signed integer Private variable _myPrivateVariable
long 64-bit signed integer Constant MyConstant
object Base type for all other types
Arrays
sbyte 8-bit signed integer
int[] array = new int[] {1, 2, 3}
short 16-bit signed integer
int[] array = {1, 2, 3}
string String value
var array = new int[] {1, 2, 3}
uint 32-bit unsigned integer
int[] array = new int[3]
ulong 64-bit unsigned integer
ushort 16-bit unsigned integer
Statements
Type Conversion Methods if-else if (true) {...}
else if (true) {...}
ToBoolean else {...}
ToByte switch switch (var) {
ToChar case 1: break;
default: break; }
ToDateTime
for for (int i =1; i < 5; i++) {...}
ToDecimal
foreach-in foreach (int item in array) {...}
ToDouble
while while (true) {...}
ToInt16
do... while do {...}
ToInt32
while (true);
ToInt64
try-catch-finally try {...}
ToSbyte catch (Exception e) {...}
ToSingle catch {...}
ToString finally {...}
ToType
ToUInt16
ToUInt32
By laurence Published 1st September, 2017. Sponsored by CrosswordCheats.com
cheatography.com/laurence/ Last updated 2nd September, 2017. Learn to solve cryptic crosswords!
Page 1 of 3. http://crosswordcheats.com
C# Cheat Sheet
by laurence via cheatography.com/42043/cs/12684/
Classes Other Modifiers
Class public class Dog {...} abstract Indicates that a class is intended only to be a base class of
Inheritance public class Dog: Pet {...} other classes
async Indicates that the modified method, lambda expression, or
Constructor (no public Dog () {...} Constructors can co-exist
anonymous method is asynchronous
parameters)
Constructor (one public Dog (string Constructors can co-exist const Specifies that the value of the field or the local variable cannot
be modified
parameter) var) {...}
event Declares an event
Field public string name
Static Class public static class Must only have static extern Indicates that the method is implemented externally
Dog {...} members new Explicitly hides a member inherited from a base class
Static Member public static int = 1 override Provides a new implementation of a virtual member inherited
from a base class
Finalizer ~Dog () {...} Cannot have modifiers or
(destructor) parameters partial Defines partial classes, structs and methods throughout the
same assembly
Access Modifiers readonly Declares a field that can only be assigned values as part of
the declaration or in a constructor in the same class
public Accessible by any other code in the same assembly or
another assembly that references it sealed Specifies that a class cannot be inherited
private Only accessible by code in the same class or struct static Declares a member that belongs to the type itself instead of to
a specific object
protected Only accessible by code in the same class or struct, or in a
derived class unsafe Declares an unsafe context
internal Accessible by any code in the same assembly, but not from virtual Declares a method or an accessor whose implementation can
another assembly be changed by an overriding member in a derived class
protected Accessible by any code in the same assembly, or by any volatile Indicates that a field can be modified in the program by
internal derived class in another assembly something such as the operating system, the hardware, or a
concurrently executing thread
By laurence Published 1st September, 2017. Sponsored by CrosswordCheats.com
cheatography.com/laurence/ Last updated 2nd September, 2017. Learn to solve cryptic crosswords!
Page 2 of 3. http://crosswordcheats.com
C# Cheat Sheet
by laurence via cheatography.com/42043/cs/12684/
Assignment Operators Logical and Bitwise Operators
= Simple assignment && Logical AND
+= Addition assignment || Logical OR
-= Subtraction assignment ! Logical NOT
*= Multiplication assignment & Binary AND
/= Division assignment | Binary OR
%= Remainder assignment ^ Binary XOR
&= AND assignment ~ Binary Ones Complement
|= OR assignment << Binary Left Shift
^ XOR assignment >> Binary Right Shift
<<= Left-shift assignment
Other Operators
>>= Right-shift assignment
sizeof() Returns the size of a data type
Comparison Operators typeof() Returns the type of a class
< Less than & Returns the address of a variable
> Greater than * Pointer to a variable
<= Less than or equal to ?: Conditional expression
>= Greater than or equal to is Determines whether an object is of a specific type
== Equal to as Cast without raising an exception if the cast fails
!= Not equal to
Arithmetic Operators
+ Add numbers
- Subtract numbers
* Multiply numbers
/ Divide numbers
% Compute remainder of division of numbers
++ Increases integer value by 1
-- Decreases integer value by 1
By laurence Published 1st September, 2017. Sponsored by CrosswordCheats.com
cheatography.com/laurence/ Last updated 2nd September, 2017. Learn to solve cryptic crosswords!
Page 3 of 3. http://crosswordcheats.com