Operators Implicitly Typed Local Variables Incrementing & Decrementing Variables... -Comments 1 -A Statement is a command that performs an action, -Comments use to explain for your Co
Trang 2Operators and Expressions
Trang 3Operators
Implicitly Typed Local
Variables
Incrementing &
Decrementing Variables
Trang 4-Comments
1
-A Statement is a command that performs an action,
-Comments use to explain for your Coding
How to write comments???
See next slide…
Trang 5//Comment 1
/*
*Comment 2
*/
/*Comment 3*/
/// <summary>
/// </summary>
/// <param name=“a"></param>
/// <param name=“b"></param>
private void func1(int a,float b)
Trang 62
Identifiers are names use to identify the elements in
Syntax Rules:
-Only use letter, digit, underscore -An identifier must start with a letter or an underscore -C# is a case –sensitive : nTest and ntest is different identifier
Trang 7abstract do in protected true
dynamic join set
from let value
group partial where
into select yield
Identifying Keywords
Trang 8- A variable is storage location that holds a value It as a box in the Computer’s memory holding temporary
information.
-To easy coding:
+Don’t start an identifier with underscore
+Start name with lower case +….
Variables
3
Trang 9How to declare variables?
Data_type NameVariable;
string strFullName;
float fValue=0,fResult;
Trang 10Data Type Description Size(bits) Range Example
int Whole numbers 32 –231 through 231 – 1 int nSize;
(bigger range) 64 –263 through 263 – 1 long lSize;
float Floating-point numbers 32 ±1.5 × 1045 through ±3.4 × 1038 float fDelta;
double
Double-precision (more accurate) floating-point numbers
64 ±5.0 × 10−324 through ±1.7 × 10308 double dDelta;
string Sequence of characters 16 bits per character Not applicable string strName;
char Single character 16 0 through 216 – 1 char chrAns;
Trang 11You should initialize value for variable
int nSize=0;
String strName=“”;
Trang 12Arithmetic
Operators
5
113 and 114 are the operands
Trang 13Not all operators are applicable to all data
types
Example:
statements:
Console.WriteLine(“Tý” - “Tèo”);
Trang 14How to convert from String to Number Format ?
int nValue=System Int32 Parse("113");
double dValue = System.Double.Parse("3.5");
Datatype vName=System DataTypeObject Parse(“ string ”);
Trang 15Incrementing &
Decrementing Variables
6
X++
Postfix increment
++X
Prefix increment
X Postfix decrement
X
Prefix decrement
Trang 16Implicitly Typed Local
Variables 7
var sAny;
Error: Implicitly-typed local variables must be initialized
var number1=1;
var strAny=“tèo”;
Trang 17END