Class
- Data or Attributes
- Methods or Functions
Namespace
- is a container for related classes
Assembly (DLL or EXE)
- is a container for related namespaces
- is a file which can either be a EXE or a DLL
Application
- include one or more assemblies
Primitive Types (C# type)
- Integral Number
- byte (1byte, Max is 255)
- short
- int
- long
- Real Numbers
- float (4byte)
- double
- decimal
- Boolean
- bool (1byte)
- good practice
- Prefix Boolean names with is or has
- For example: isOver18, isCitizen, isEligible
Something tricky about real numbers
- data type is double by default
float number = 1.2;
decimal number = 1.2;
float number = 1.2f;
decimal number = 1.2m;
Non-Primitive Types
Overflowing
byte number = 255;
number = number + 1; //0
- if you use check keyword, overflow will not happen and instead the program will throw an exception (But don‘t use it in real world )
Scope
- where a variable / constant has meaning
Type Conversion
- explicit type conversion (casting)
int c = 1;
byte d = (byte)c;
- conversion between non-compatible types
string e = "100";
int f = int.Parse(e)
var a = "1234";
int b = Convert.ToInt32(a);
C# Operators
var a = 10;
var b = 3;
Console.WriteLine(a+b); // 3
Console.WriteLine((float)a / (float)b); // 3.333333
int a = 1;
int b = a++; //b = 1, a = 2;
int a = 1;
int b = ++a; //b = 2, a = 2;
- Logical Operator
- &&
- And
- double ampersand
- a&&b
- ||
- Or
- double vertical line
- a||b
- !
Comments
// Here is a single-line comment
/*
Here is a multi-line
comment
*/
- When to use comments
- to explain whys, hows, constrains, etc
- Not explain the whats.
- comment do not explain what the code is doing
Primitive Types and Expressions
原文:http://www.cnblogs.com/jarodli/p/8016168.html