Show Menu
Cheatography

C A-Z Cheat Sheet (DRAFT) by

c#

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Data Types

Numbers: double, int, byte, short, long, float
Text: char, string
Other: bool, object
case-s­ens­itive

Comments

// - line comment
/*...*/ - multiple line comment

Operators

+, -, *, /, % - standard operators
++ and -- - increm­ent­/de­crement by 1
== and != - is equal and not equal
&& - and
|| - or
is - determines whether an object is of a certain type
sizeof() - size of a data type
typeof() - type of a class

Loops

while <co­ndi­tio­n> { statem­ent(s) }; - the WHILE DO loop
for (init;­con­dit­ion­;in­cre­ment) { statem­ent(s) }; - the FOR loop
do { statem­ent(s) } while <co­ndi­tio­n> - the DO WHILE loop

for (int a = 10; a < 20; a = a + 1)

{

Consol­e.W­rit­eLi­ne(­"­value of a: {0}", a);

 }


while (a<10)

{

a++;

}
 

Files and I/O

Consol­e.W­rit­e(Line) - writes a line
Consol­e.R­ead­(Line) - reads input
Stream­Writer - used for writing characters to a stream
FileStream - used to read from and write to any location in a file

FileStream <ob­jec­t_n­ame> = new FileSt­ream( <fi­le_­nam­e>, <Fi­leMode Enumer­ato­r>, <Fi­leA­ccess Enumer­ato­r>, <Fi­leShare Enumer­ato­r>)

Consol­e.W­rit­eLi­ne=­("Use the Force, Luke!")


FileStream F = new FileSt­rea­m("s­amp­le.t­xt­", FileMo­de.O­pen, FileAc­ces­s.Read, FileSh­are.Read);

Decision Making

if <co­ndi­tio­n> { statem­ent(s) } else { statem­ent(s) } - the IF statement

switch (variable) { case value1: statem­ent(s) break; ... default: statem­ent(s) break; } - the SWITCH statement

if (a==10)

{

a++;

}


switch (a)

{

case 1: Consol­e.W­rit­eLi­ne(­"a is 1");

break;

default: Consol­e.W­rit­eLi­ne(­"a is not 1");

break;

}
 

Classes

class <cl­ass­_na­me> - class declar­ation
<cl­ass­_na­me> <ob­jec­t_n­ame> = new <cl­ass­_na­me> - object creation

class Box

{

public double length;

public double breadth;

public double height

}

static void Main(s­tring[] args)

{

 Box Box1 = new Box();

 Box1.h­eight = 5.0;

          Box1.l­ength = 6.0;

        Box1.b­readth = 7.0;

}

Access Specifiers

public - can be accessed from anywhere
private - only inside the class
protected - hides it from other classes; used in child classes
internal - hides it from another namespace