Data Types
Numbers: double, int, byte, short, long, float
Text: char, string
Other: bool, object |
Comments
// - line comment
/*...*/ - multiple line comment |
Operators
+, -, *, /, % - standard operators
++ and -- - increment/decrement 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 <condition> { statement(s) }; - the WHILE DO loop
for (init;condition;increment) { statement(s) }; - the FOR loop
do { statement(s) } while <condition> - the DO WHILE loop
for (int a = 10; a < 20; a = a + 1)
{
Console.WriteLine("value of a: {0}", a);
}
while (a<10)
{
a++;
}
|
|
|
Files and I/O
Console.Write(Line) - writes a line
Console.Read(Line) - reads input
StreamWriter - used for writing characters to a stream
FileStream - used to read from and write to any location in a file
FileStream <object_name> = new FileStream( <file_name>, <FileMode Enumerator>, <FileAccess Enumerator>, <FileShare Enumerator>)
Console.WriteLine=("Use the Force, Luke!")
FileStream F = new FileStream("sample.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
|
Decision Making
if <condition> { statement(s) } else { statement(s) } - the IF statement
switch (variable) { case value1: statement(s) break; ... default: statement(s) break; } - the SWITCH statement
if (a==10)
{
a++;
}
switch (a)
{
case 1: Console.WriteLine("a is 1");
break;
default: Console.WriteLine("a is not 1");
break;
}
|
|
|
Classes
class <class_name> - class declaration
<class_name> <object_name> = new <class_name> - object creation
class Box
{
public double length;
public double breadth;
public double height
}
static void Main(string[] args)
{
Box Box1 = new Box();
Box1.height = 5.0;
Box1.length = 6.0;
Box1.breadth = 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 |
|