intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Bài giảng Lập trình C# 2010: Chương 1.1 - ĐH Công nghệ Đồng Nai

Chia sẻ: Na Na | Ngày: | Loại File: PPTX | Số trang:17

113
lượt xem
13
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Bài giảng Lập trình C# 2010: Chương 1.1 trình bày các nội dung về Working with Variables, Operators and Expressions (làm việc với biến, khai thác và những biểu hiện) trình bày các khái niệm, đặc điểm, công dụng và các nội dung khác.

Chủ đề:
Lưu

Nội dung Text: Bài giảng Lập trình C# 2010: Chương 1.1 - ĐH Công nghệ Đồng Nai

  1. DONG NAI UNIVERSITY OF TECHNOLOGY
  2. DONG NAI UNIVERSITY OF TECHNOLOGY Working with Variables, Operators and Expressions
  3. DONG NAI UNIVERSITY OF TECHNOLOGY 1 2 3 Statement Identifiers Variables s - Comment4 5 Primitive Arithmeti s Data c Types Operators 6 7 Incrementing Implicitly & Typed Local Decrementing Variables Variables
  4. DONG NAI UNIVERSITY OF TECHNOLOGY -A Statement is a command that performs an action, you must add “;” the end of 1 command Statement -Ex: Console.Write(“Hello s C# ”); -Comments use to explain - Comment for your Coding s How to write comments??? See next slide…
  5. DONG NAI UNIVERSITY OF TECHNOLOGY //Comment 1 /// ///Write Comment 4 /* /// *Comment 2 /// private void func1(int a,float b)
  6. DONG NAI UNIVERSITY OF TECHNOLOGY Identifiers are names use to identify the elements in program, ex: namespace, 2 class, method… Identifiers 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
  7. DONG NAI UNIVERSITY OF TECHNOLOGY Identifying Keywords abstract do in protected true as double int public try base else interface readonly typeof bool enum internal ref uint 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 null stackalloc virtual class float object static void const for operator string volatile continue foreach out struct while decimal goto override switch default if params this delegate implicit private throw dynamic join set from let value get orderby var group partial where into select yield
  8. DONG NAI UNIVERSITY OF TECHNOLOGY - A variable is storage location that holds a value. It as a box in the Computer’s memory 3 holding temporary Variables 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 +….
  9. DONG NAI UNIVERSITY OF TECHNOLOGY How to declare variables? Data_type NameVariable; int nNumberOfElement; string strFullName; float fValue=0,fResult;
  10. DONG NAI UNIVERSITY OF TECHNOLOGY 4 Primitive Data Types Data Type Description Size(bits) Range Example –231 through 231 – int Whole numbers 32 int nSize; 1 Whole numbers –263 through 263 – long 64 long lSize; (bigger range) 1 Floating-point ±1.5 × 1045 through float 32 float fDelta; numbers ±3.4 × 1038 Double- precision (more ±5.0 × 10−324 double accurate) 64 through ±1.7 × double dDelta; floating-point 10308 numbers Monetary decimal decimal 128 28 significant figures values decKe; Sequence of 16 bits per string string Not applicable characters character strName; char Single character 16 0 through 216 – 1 char chrAns; bool Boolean 8 True or false bool bRet;
  11. DONG NAI UNIVERSITY OF TECHNOLOGY You should initialize value for variable int nSize=0; String strName=“”;
  12. DONG NAI UNIVERSITY OF TECHNOLOGY + - * 5 Arithmeti c / % () Operators int nPlusTwoNumber=113 + 114 The + is the operator 113 and 114 are the operands
  13. 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ý” -
  14. 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”);
  15. DONG NAI UNIVERSITY OF TECHNOLOGY X++ ++X Postfix Prefix 6 increme increment Incrementing & nt Decrementing X-- --X Variables Postfix Prefix decreme decremen nt t
  16. DONG NAI UNIVERSITY OF TECHNOLOGY 7 Implicitly var number1=1; Typed Local Variables var strAny=“tèo”; var sAny; Error: Implicitly-typed local variables must be initialized
  17. DONG NAI UNIVERSITY OF TECHNOLOGY END
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
17=>2