cs-cheat-sheet.pdf

(634 KB) Pobierz
© THECODINGGUYS 2013
C# Cheat Sheet
12/24/2013
A cheat sheet to the C# language, ideal for newcomers to the language for more visit
http://www.thecodingguys.net
K
EEP IN TOUCH
TABLE OF CONTENTS
LICENSE
LANGUAGE BASICS
Introduction
Variables
Syntax
Naming Rules
Example
Arrays
Syntax
Example
Strings
Concatenation
Example
New Line
Example
String.Format
Example
3
4
4
4
4
4
4
4
4
5
5
5
5
5
5
5
5
CONDITIONAL STATEMENTS
If statements
Syntax
Example
If Else Statements
Example
Switch Statement
Syntax
Example
6
6
6
6
6
6
6
7
7
LOOPS
While Loop
Syntax
Example
For Loop
Syntax
Example
8
8
8
8
8
8
9
For Each
Syntax
Example
9
9
9
ADVANCED – EXCEPTIONS, METHODS & CLASSES
Exceptions
Syntax
Example
Methods
Syntax
Example
Passing Parameters
Returning Data
Classes
Syntax
Example
10
10
10
10
10
10
11
11
11
12
12
12
SUMMARY
Why Not Give us a like?
12
12
LICENSE
This work is licensed under the creative commons Attribution-NonCommercial-NoDerivs
3.0
Unported
You may not alter, transform, or build upon this work.
You may not use this work for commercial purposes.
You are free to copy, distribute and transmit the work
L
ANGUAGE
B
ASICS
I
NTRODUCTION
C# is a powerful Object Orientated language, for those coming from Java or C++ you should be
able to pick up the syntax for C# quickly. A few points:
The language is case-sensitive (So A and a are different)
Lines terminate with semi-colons
Code is put in code blocks { }
Inline comments start with //
Block comments start with /* */
XML comments start with ///
V
ARIABLES
To declare a variable you specify the data type and variable name followed by a value.
S
YNTAX
DataType
variableName = value;
N
AMING
R
ULES
Variables must start with underscore or letter
Variables cannot contain spaces
variables can contain numbers
Cannot contain symbols (accept underscore)
E
XAMPLE
string
Name =
"thecodingguys";
int
Year = 2013;
I will use these two variables throughout.
A
RRAYS
Arrays are similar to variables, but can hold more than one value.
S
YNTAX
DataType[ ]
ArrayName = { Comma Separated Values }
// Array of any size
DataType[]
ArrayName =
new DataType[3]
{Command Separated Values }
//Expects 3 values
Zgłoś jeśli naruszono regulamin