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

Bài giảng Lập trình C# 2010: Chương 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. | 1 Working with Variables, Operators and Expressions 2 Statements -Comments Identifiers Variables Primitive Data Types Arithmetic Operators Implicitly Typed Local Variables Incrementing & Decrementing Variables 1 2 3 4 5 6 7 3 Statements -Comments 1 -A Statement is a command that performs an action, you must add “;” the end of command -Ex: (“Hello C# ”); -Comments use to explain for your Coding How to write comments??? See next slide 4 //Comment 1 /* *Comment 2 */ /*Comment 3*/ /// ///Write Comment 4 /// /// /// private void func1(int a,float b) 5 Identifiers 2 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 6 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 Identifying Keywords 7 - 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 + . Variables 3 8 How to declare variables? Data_type NameVariable; int nNumberOfElement; string strFullName; float fValue=0,fResult; 9 Data Type Description Size(bits) Range Example int 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 ± × 1045 through ± × 1038 float fDelta; double Double-precision (more accurate) floating-point numbers 64 ± × 10−324 through ± × 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 Types 4 10 You should initialize value for variable int nSize=0; String strName=“”; Arithmetic Operators 5 + - * / % () int nPlusTwoNumber=113 + 114 The + is the operator 113 and 114 are the operands 12 Not all operators are applicable to all data types Example: You will get compiler error with the statements: (“Tý” - “Tèo”); 13 How to convert from String to Number Format ? int nValue=("113"); double dValue = (""); Datatype vName=(“string”); 14 Incrementing & Decrementing Variables 6 X++ Postfix increment ++X Prefix increment X-- Postfix decrement --X Prefix decrement 15 Implicitly Typed Local Variables 7 var sAny; Error: Implicitly-typed local variables must be initialized var number1=1; var strAny=“tèo”; 16 END 17

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.