Bài giảng lập trình c 2010 chương 1 1 đh công nghệ đồng nai

17 206 0
Bài giảng lập trình c 2010  chương 1 1   đh công nghệ đồng nai

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

DONG NAI UNIVERSITY OF TECHNOLOGY DONG NAI UNIVERSITY OF TECHNOLOGY Working with Variables, Operators and Expressions DONG NAI UNIVERSITY OF TECHNOLOGY Statements -Comments Identifiers Primitive Data Types Variables Arithmetic Operators Incrementing & Decrementing Variables Implicitly Typed Local Variables DONG NAI UNIVERSITY OF TECHNOLOGY -A Statement is a command that performs an action, you must add “;” the end of command -Ex: Console.Write(“Hello C# ”); Statements -Comments -Comments use to explain for your Coding How to write comments??? See next slide… DONG NAI UNIVERSITY OF TECHNOLOGY //Comment /// ///Write Comment /* /// *Comment /// private void func1(int a,float b) /*Comment 3*/ DONG NAI UNIVERSITY OF TECHNOLOGY Identifiers are names use to identify the elements in program, ex: namespace, class, method… Syntax Rules: Identifiers -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 DONG NAI UNIVERSITY OF TECHNOLOGY Identifying Keywords abstract in protected as double int base else interface readonly bool enum internal ref break event is return ulong byte explicit lock sbyte unchecked case extern long sealed unsafe catch false namespace short ushort char finally new sizeof using checked fixed public true null class float object const for operator foreach out decimal goto override if params implicit private dynamic join set from let value get orderby group partial where into select yield var virtual void string volatile struct while switch this delegate typeof uint stackalloc static continue default try throw DONG NAI UNIVERSITY OF TECHNOLOGY - 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 Variables +Don’t different only by case ( nTest and ntest) +Start name with lower case +… DONG NAI UNIVERSITY OF TECHNOLOGY How to declare variables? Data_type NameVariable; int nNumberOfElement; string strFullName; float fValue=0,fResult; DONG NAI UNIVERSITY OF TECHNOLOGY Primitive Data Types Data Type Description Size(bits) int Whole numbers 32 Range 31 31 –2 through – 64 63 63 –2 through – long lSize; 32 45 38 ±1.5 × 10 through ±3.4 × 10 float fDelta; 64 ±5.0 × 10 long float Whole numbers (bigger range) Floating-point numbers Double-precision (more double accurate) floating-point −324 through ±1.7 × 10 Example int nSize; 308 double dDelta; numbers 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 through bool Boolean True or false 16 –1 char chrAns; bool bRet; DONG NAI UNIVERSITY OF TECHNOLOGY You should initialize value for variable int nSize=0; String strName=“”; DONG NAI UNIVERSITY OF TECHNOLOGY Arithmetic Operators + - * / % () int nPlusTwoNumber=113 + 114 The + is the operator 113 and 114 are the operands DONG NAI UNIVERSITY OF TECHNOLOGY Not all operators are applicable to all data types Example: You will get compiler error with the statements: Console.WriteLine(“Tý” - “Tèo”); DONG NAI UNIVERSITY OF TECHNOLOGY 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”); DONG NAI UNIVERSITY OF TECHNOLOGY X++ ++X Postfix increment Prefix increment X X Postfix decrement Prefix decrement Incrementing & Decrementing Variables DONG NAI UNIVERSITY OF TECHNOLOGY Implicitly Typed Local Variables var number1=1; var strAny=“tèo”; var sAny; Error: Implicitly-typed local variables must be initialized DONG NAI UNIVERSITY OF TECHNOLOGY END [...]...DONG NAI UNIVERSITY OF TECHNOLOGY You should initialize value for variable int nSize=0; String strName=“”; DONG NAI UNIVERSITY OF TECHNOLOGY 5 Arithmetic Operators + - * / % () int nPlusTwoNumber =11 3 + 11 4 The + is the operator 11 3 and 11 4 are the operands DONG NAI UNIVERSITY OF TECHNOLOGY Not all operators are applicable to all data types Example: You will get compiler error with the statements: Console.WriteLine(“Tý”... DONG NAI UNIVERSITY OF TECHNOLOGY How to convert from String to Number Format ? int nValue=System.Int32.Parse( "11 3"); double dValue = System.Double.Parse("3.5"); Datatype vName=System.DataTypeObject.Parse(“string”); DONG NAI UNIVERSITY OF TECHNOLOGY X++ ++X Postfix increment Prefix increment X X Postfix decrement Prefix decrement 6 Incrementing & Decrementing Variables DONG NAI UNIVERSITY OF TECHNOLOGY... X X Postfix decrement Prefix decrement 6 Incrementing & Decrementing Variables DONG NAI UNIVERSITY OF TECHNOLOGY 7 Implicitly Typed Local Variables var number1 =1; var strAny=“tèo”; var sAny; Error: Implicitly-typed local variables must be initialized DONG NAI UNIVERSITY OF TECHNOLOGY END ... dDelta; numbers decimal Monetary values 12 8 28 significant figures decimal decKe; string Sequence of characters 16 bits per character Not applicable string strName; char Single character 16 through... unchecked case extern long sealed unsafe catch false namespace short ushort char finally new sizeof using checked fixed public true null class float object const for operator foreach out decimal... nPlusTwoNumber =11 3 + 11 4 The + is the operator 11 3 and 11 4 are the operands DONG NAI UNIVERSITY OF TECHNOLOGY Not all operators are applicable to all data types Example: You will get compiler error

Ngày đăng: 03/12/2015, 18:30

Từ khóa liên quan

Mục lục

  • Slide 1

  • Slide 2

  • Slide 3

  • Slide 4

  • Slide 5

  • Slide 6

  • Slide 7

  • Slide 8

  • Slide 9

  • Slide 10

  • Slide 11

  • Slide 12

  • Slide 13

  • Slide 14

  • Slide 15

  • Slide 16

  • Slide 17

Tài liệu cùng người dùng

Tài liệu liên quan