Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 183 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
183
Dung lượng
2,28 MB
Nội dung
An Introduction to Object Oriented Programming with C# Dr Kieran Mulchrone Department of Applied Mathematics, University College, Cork September 2010 CONTENTS Introduction 1.1 A Brief History of C# 1.2 What is the NET framework? 1.3 The C# Programming Environment 1.3.1 Generic Considerations 1.3.2 Microsoft Visual C# express edition 1.3.3 Creating your First C# Program "Hello World!" 1.3.4 Comments 9 10 11 11 11 12 15 Object Orientation 2.1 Introduction 2.2 What is Object Oriented Programming (OOP)? 2.3 Object Oriented Vocabulary 2.3.1 Objects 2.3.2 Classes 2.3.3 Encapsulation and Interfaces 2.3.4 Data Abstraction 2.3.5 Problem Solving with Objects and Object Interactions 2.3.6 Inheritance 2.3.7 Polymorphism 17 17 17 18 18 19 19 20 20 22 23 25 25 25 25 26 26 26 27 27 27 28 Data Types, Variables, I/O and Operators 3.1 Introduction 3.2 Data Types 3.2.1 Introduction 3.2.2 Data type char 3.2.3 Integer Data Types 3.2.4 Data Types double and ‡oat 3.3 Variables 3.3.1 Introduction 3.3.2 Declaration of Variables 3.3.3 Naming of Variables CONTENTS 3.3.4 Initialising Variables and Assigning Values to Variables, C# requires de…nite assignment 3.3.5 Constants 3.4 Console Input/Output (I/O) 3.4.1 Introduction 3.4.2 Output 3.4.3 Input 3.5 Operators 3.5.1 Assignment = 3.5.2 Arithmetic Operators (+, -, *, /, %) 3.5.3 Integer Division 3.5.4 The Modulus Operator 3.5.5 Increment and Decrement operators (++, - -) 3.5.6 Special Assignment Operators (+=, -=, *=, /=, %=, &=, >>=, [...]... various menu options and toolbar options The primary purpose of this document is to explain the art of C# programming and therefore only a brief introduction to the Visual Studio C# environment is given A fuller discussion of the use of Visual Studio C# can be found on-line or in the help system 1.3.3 Creating your First C# Program "Hello World!" In this section a step by step guide to creating your …rst... then we can drop the namespace pre…x Lets look at the code! The …rst line using System; is an instruction that we may want to use one or more objects de…ned in the System namespace (this is a namespace full of goodies programmed by somebody else but available for us to use) Next we de…ne our own namespace (this can be called anything) Inside the namespace we create a class called by default Program we... confused between the syntax of the language and object orientation To avoid this happening, the fundamental concepts of the object oriented approach are tackled in plain English with real-world examples Hopefully this method of presentation allows the reader to come to grips with the object oriented vocabulary before exposure to the C# syntax which supports it All of the concepts discussed here will be returned... produce some output data The logical manipulation should consist of a step by step linear series of operations ultimately giving the required answer Our program will simply consist of a long list of (hopefully logical) instructions to be performed What if we had to do the some portion of the sequence of instructions twice? Well, we would have to copy the required sequence of commands to another place in... numbers and underscores only 3 Reserved words (e.g words that already have a special purpose int he language such as int, char and double) cannot be used as variable names In addition, please note carefully that C# is case sensitive For example, the identi…ers Rate, rate and RATE are all considered to be di¤erent by the C# compiler This is a common source of compiler error and programming error It is