Show Menu
Cheatography

Visual C# 2008 - Basic knowledge - Grammar Cheat Sheet (DRAFT) by

Visual C# 2008 - Grammar Basic knowledge.

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

Variable declar­ation

double douNum;
① Data Type + Variable
douNum = 777;
① Use "­=" when substi­tuting a value.
string strName = "­Tes­t";
② Declar­ation and assign­ment.
int iID = 157, iPW = 653;
③ ②+④
bool bFlg, bFLG;
④ If the data types are the same, they can be declared together.
bFlg = true;
⑤ Be case-s­ens­itive.
bFLG = false;
⑤ Be case-s­ens­itive.

Type of data type

sbyte
Signed 8bit
-128~127
System.SByte
byte
Unsigned 8bit
0~255
System.Byte
short
Signed 16bit
-32,76­8~3­2,767
System.Int16
ushort
Unsigned 16bit
0~65,535
System.UInt16
int
Signed 32bit
-2,147­,48­3,6­48~­2,1­47,­483,647
System.Int32
uint
Unsigned 32bit
0~4,29­4,9­67,295
System.UInt32
long
Signed 64bit
-9,223­,37­2,0­36,­854­,77­5,8­08~­9,2­23,­372­,03­6,8­54,­775,807
System.Int64
ulong
Unsigned 64bit
0~18,4­46,­744­,07­3,7­09,­551,615
System.UInt64
float
32bit
±1.5×1­0(-­45)­~±3.4×­10(38)
System.Single
double
64bit
±5.0×1­0(-­324­)~±­1.7­×10­(308)
System.Double
decimal
128bit
±1.0×1­0(-­28)­~±7.9×­10(28)
System.De­cimal
char
16bit
0~65535 Unicode
System.Char
bool
bool type
True or False
System.Bo­olean
string
string type
0~2 billion this Unicode
System.String
object
object type
Any type
System.Object

Variable Scope

Access modifier type

public
Access from outside is also OK.
protected
Only in Class and from Derived Class.
internal
Only in the same assembly.
private
Only in the class in which it is declared.

Literal

Literal
Data that directly expresses a value.
Bool Literal
True or False
Prefix
Add to the front.
Char Literal
Enclose with ''.
Suffix
Add to the end.
String Literal
Enclose with "­".
Number Literal
L or l : long
U or u : uint or ulong
UL or ul : ulong
Real number
F or f : float
D or d : double
M or m : decimal
Point : Numerical types other than decimal type are binary numbers. Decimal type is decimal.
Perfect accuracy : Decimal, Other than that : double, Memory savings : float

Cast

Implicit type conversion
int ➝ double : OK
Explicit type conversion
double dNum ➝ int iNum = dNum : OK
Implicit cast
double ➝ int : NG
Explicit cast
srting strNum ➝ int
int.Pa­rse­(st­rNum);
int iNum ➝ string
iNum.T­oSt­ring();
Caution :
Digit loss (floating point only)
Inform­ation loss (floating point only)
Rounding error (both fixed and floating point)
Truncation error (both fixed and floating point)

Naming convention

Hungarian notation
Data type + word
strName
Pascal format
Capitalize each word.
UserName
Camel format
The initials of the first word are lowercase. The initials of the latter words are capital letters.
userFi­rstName
Snake format
Underbar when connecting words.
user_f­irs­t_name