working with variables, operators and expressions
Post on 04-Jan-2016
34 Views
Preview:
DESCRIPTION
TRANSCRIPT
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
Working with Variables, Operators and Expressions
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
Statements-Comments
Identifiers Variables
Primitive Data Types
Arithmetic Operators
Implicitly Typed Local
Variables
Incrementing & Decrementing
Variables
1 2 3
4 5
6 7
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
Statements-Comments
1
-A Statement is a command that performs an action, you must add “;” the end of command-Ex: Console.Write(“Hello C# ”);
-Comments use to explain for your CodingHow to write comments???See next slide…
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
//Comment 1
/* *Comment 2 */
/*Comment 3*/
/// <summary>///Write Comment 4/// </summary>/// <param name=“a"></param>/// <param name=“b"></param>private void func1(int a,float b)
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
Identifiers2
Identifiers are names use to identify the elements in program, ex: namespace, class, method…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
abstract do in protected trueas double int public trybase else interface readonly typeofbool enum internal ref uintbreak event is return ulongbyte explicit lock sbyte uncheckedcase extern long sealed unsafecatch false namespace short ushortchar finally new sizeof usingchecked fixed null stackalloc virtualclass float object static voidconst for operator string volatilecontinue foreach out struct whiledecimal goto override switchdefault if params thisdelegate implicit private throwdynamic join setfrom let valueget orderby vargroup partial whereinto select yield
Identifying Keywords
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
- 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+Don’t different only by case ( nTest and ntest)+Start name with lower case +….
Variables3
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
How to declare variables?
Data_type NameVariable;int nNumberOfElement;string strFullName;float fValue=0,fResult;
Data Type Description Size(bits) Range Exampleint Whole numbers 32 –231 through 231 – 1 int nSize;
long Whole numbers(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;
decimal Monetary values 128 28 significant figures decimal decKe;
string Sequence of characters
16 bits per character Not applicable string strName;
char Single character 16 0 through 216 – 1 char chrAns;bool Boolean 8 True or false bool bRet;
Primitive Data Types4
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
You should initialize value for variableint nSize=0;String strName=“”;
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
Arithmetic Operators
5
+ - *
/ % ()int nPlusTwoNumber=113 + 114The + is the operator113 and 114 are the operands
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
Not all operators are applicable to all data typesExample:You will get compiler error with the statements:Console.WriteLine(“Tý” - “Tèo”);
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
How 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”);
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
Incrementing & Decrementing
Variables
6
X++Postfix
increment
++XPrefix
increment
X--Postfix
decrement
--XPrefix
decrement
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
Implicitly Typed Local
Variables
7
var sAny;Error: Implicitly-typed local variables must be initialized
var number1=1;var strAny=“tèo”;
FACULTY OF IMFORMATION TECHNOLOGY
Author: Nguyen Ngoc Khuong– Phone : 0976649996- Email: khuongnn.mcs09@vnuedu.vn– Blog: http://khuongfit.wordpress.com
HAI PHONG UNIVERSITY
END
top related