Variable declaration
double douNum; |
① Data Type + Variable |
douNum = 777; |
① Use "=" when substituting a value. |
string strName = "Test"; |
② Declaration and assignment. |
int iID = 157, iPW = 653; |
③ ②+④ |
bool bFlg, bFLG; |
④ If the data types are the same, they can be declared together. |
bFlg = true; |
⑤ Be case-sensitive. |
bFLG = false; |
⑤ Be case-sensitive. |
Type of data type
sbyte |
Signed 8bit |
-128~127 |
System.SByte |
byte |
Unsigned 8bit |
0~255 |
System.Byte |
short |
Signed 16bit |
-32,768~32,767 |
System.Int16 |
ushort |
Unsigned 16bit |
0~65,535 |
System.UInt16 |
int |
Signed 32bit |
-2,147,483,648~2,147,483,647 |
System.Int32 |
uint |
Unsigned 32bit |
0~4,294,967,295 |
System.UInt32 |
long |
Signed 64bit |
-9,223,372,036,854,775,808~9,223,372,036,854,775,807 |
System.Int64 |
ulong |
Unsigned 64bit |
0~18,446,744,073,709,551,615 |
System.UInt64 |
float |
32bit |
±1.5×10(-45)~±3.4×10(38) |
System.Single |
double |
64bit |
±5.0×10(-324)~±1.7×10(308) |
System.Double |
decimal |
128bit |
±1.0×10(-28)~±7.9×10(28) |
System.Decimal |
char |
16bit |
0~65535 Unicode |
System.Char |
bool |
bool type |
True or False |
System.Boolean |
string |
string type |
0~2 billion this Unicode |
System.String |
object |
object type |
Any type |
System.Object |
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.Parse(strNum); |
int iNum ➝ string |
iNum.ToString(); |
Caution :
Digit loss (floating point only)
Information 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. |
userFirstName |
Snake format |
Underbar when connecting words. |
user_first_name |
|